mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Cleaned up rsPeers to remove 10 minute reconnect. The reconnect was caused by
the periodical call of cleanupUsedLocation, which was reloading all the GPG Keys - for each cleanup Key. This required cleaning up various bits (AuthGPG, rsPeers, p3Disc). * moved rsPeer::cleanUnusedLocations => p3PeerMgr::removeUnusedLocations(); - made the function light-weight, no loading of GPG Keys. * moved getSSLCertsFromGPG() fn from rsPeers => p3PeerMgr * added p3PeerMgr::removeAllFriendLocations() to cleanup when removing a GPG Friend. * cleaned up rsPeers, made addFriend() / removeFriend() universal functions. * remove bool p3Peers::setAcceptToConnectGPGCertificate(const std::string &gpg_id, bool acceptance) * removed all Dummy SSL Ids. - There is no need for this! * Major changes to p3disc to correct FLAWED logic. (needs more testing). * removed as many dependancies on retroshare/rspeer.h as possible. * changed p3turtle dependancy on rsPeers ==> mLinkMgr. * added p3LinkMgr::getPeerName() and p3PeerMgr::getPeerName() * added return 1 to pqissllistener::closeConnection(). * removed unused code from AuthGPG(). * removed storeAllKeys() calls in AuthGPG::AllowConnection(). git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4542 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
80629c5d9b
commit
8e3e7d5209
@ -25,8 +25,9 @@
|
||||
*/
|
||||
|
||||
#include "authgpg.h"
|
||||
#include "retroshare/rsiface.h"
|
||||
#include "retroshare/rsinit.h"
|
||||
#include "retroshare/rsiface.h" // For rsicontrol.
|
||||
#include "retroshare/rspeers.h" // For RsPeerDetails.
|
||||
|
||||
#include <util/rsdir.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
@ -64,18 +65,10 @@ AuthGPG *AuthGPG::getAuthGPG()
|
||||
}
|
||||
|
||||
/* Turn a set of parameters into a string */
|
||||
#if 0
|
||||
static std::string setKeyPairParams(bool useRsa, unsigned int blen,
|
||||
std::string name, std::string comment, std::string email);
|
||||
#endif
|
||||
static std::string setKeyPairParams(bool useRsa, unsigned int blen,
|
||||
std::string name, std::string comment, std::string email,
|
||||
std::string inPassphrase);
|
||||
|
||||
#ifdef UNUSED_CODE
|
||||
static gpgme_key_t getKey(gpgme_ctx_t, std::string, std::string, std::string);
|
||||
#endif
|
||||
|
||||
static gpg_error_t keySignCallback(void *, gpgme_status_code_t, \
|
||||
const char *, int);
|
||||
|
||||
@ -152,15 +145,6 @@ AuthGPGimpl::AuthGPGimpl()
|
||||
gpgme_set_locale(NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
|
||||
#endif
|
||||
|
||||
#ifndef WINDOWS_SYS
|
||||
/* setup the engine (gpg2) */
|
||||
// if (GPG_ERR_NO_ERROR != gpgme_set_engine_info(GPGME_PROTOCOL_OpenPGP, "/usr/bin/gpg2", NULL))
|
||||
// {
|
||||
// std::cerr << "Error creating Setting engine" << std::endl;
|
||||
// return;
|
||||
// }
|
||||
#endif
|
||||
|
||||
if (GPG_ERR_NO_ERROR != gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP))
|
||||
{
|
||||
std::cerr << "Error check engine version" << std::endl;
|
||||
@ -995,12 +979,6 @@ bool AuthGPGimpl::VerifySignature(const void *data, int datalen, const void *sig
|
||||
|
||||
RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/
|
||||
|
||||
// if(siglen==73)
|
||||
// {
|
||||
// //std::cerr << "Reducing to 72 to overcome an old bug." << std::endl ;
|
||||
// siglen=72 ;
|
||||
// }
|
||||
|
||||
if (GPG_ERR_NO_ERROR != gpgme_data_new_from_mem(&gpgmeData, (const char *) data, datalen, 1))
|
||||
{
|
||||
std::cerr << "Error create Data" << std::endl;
|
||||
@ -1515,25 +1493,24 @@ bool AuthGPGimpl::LoadCertificateFromString(const std::string &str, std::string
|
||||
/*************************************/
|
||||
|
||||
/* These take PGP Ids */
|
||||
bool AuthGPGimpl::setAcceptToConnectGPGCertificate(const std::string &gpg_id, bool acceptance)
|
||||
bool AuthGPGimpl::AllowConnection(const std::string &gpg_id, bool accept)
|
||||
{
|
||||
|
||||
#ifdef GPG_DEBUG
|
||||
std::cerr << "AuthGPGimpl::markGPGCertificateAsFriends(" << gpg_id << ")" << std::endl;
|
||||
std::cerr << "AuthGPGimpl::AllowConnection(" << gpg_id << ")" << std::endl;
|
||||
#endif
|
||||
|
||||
/* reload stuff now ... */
|
||||
storeAllKeys();
|
||||
/* Was a "Reload Certificates" here -> be shouldn't be needed -> and very expensive, try without. */
|
||||
{
|
||||
RsStackMutex stack(gpgMtxData);
|
||||
certmap::iterator it;
|
||||
if (mKeyList.end() == (it = mKeyList.find(gpg_id))) {
|
||||
if (mKeyList.end() == (it = mKeyList.find(gpg_id)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
it->second.accept_connection = acceptance;
|
||||
mAcceptToConnectMap[gpg_id] = acceptance;
|
||||
it->second.accept_connection = accept;
|
||||
mAcceptToConnectMap[gpg_id] = accept;
|
||||
}
|
||||
storeAllKeys();
|
||||
|
||||
IndicateConfigChanged();
|
||||
|
||||
@ -1730,69 +1707,6 @@ int AuthGPGimpl::privateTrustCertificate(const std::string &id, int trustlvl)
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* This function to print Data */
|
||||
#if 0
|
||||
void showData(gpgme_data_t dh)
|
||||
{
|
||||
#define BUF_SIZE 512
|
||||
char buf[BUF_SIZE + 1];
|
||||
int ret;
|
||||
|
||||
ret = gpgme_data_seek (dh, 0, SEEK_SET);
|
||||
if (ret)
|
||||
{
|
||||
std::cerr << "Fail data seek" << std::endl;
|
||||
// fail_if_err (gpgme_err_code_from_errno (errno));
|
||||
}
|
||||
|
||||
while ((ret = gpgme_data_read (dh, buf, BUF_SIZE)) > 0)
|
||||
fwrite (buf, ret, 1, stdout);
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
std::cerr << "Fail data seek" << std::endl;
|
||||
//fail_if_err (gpgme_err_code_from_errno (errno));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
static std::string setKeyPairParams(bool useRsa, unsigned int blen,
|
||||
std::string name, std::string comment, std::string email)
|
||||
{
|
||||
std::ostringstream params;
|
||||
params << "<GnupgKeyParms format=\"internal\">"<< std::endl;
|
||||
if (useRsa)
|
||||
{
|
||||
params << "Key-Type: RSA"<< std::endl;
|
||||
if (blen < 1024)
|
||||
{
|
||||
#ifdef GPG_DEBUG
|
||||
std::cerr << "Weak Key... strengthing..."<< std::endl;
|
||||
#endif
|
||||
blen = 1024;
|
||||
}
|
||||
blen = ((blen / 512) * 512); /* make multiple of 512 */
|
||||
params << "Key-Length: "<< blen << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
params << "Key-Type: DSA"<< std::endl;
|
||||
params << "Key-Length: 1024"<< std::endl;
|
||||
params << "Subkey-Type: ELG-E"<< std::endl;
|
||||
params << "Subkey-Length: 1024"<< std::endl;
|
||||
}
|
||||
params << "Name-Real: "<< name << std::endl;
|
||||
params << "Name-Comment: "<< comment << std::endl;
|
||||
params << "Name-Email: "<< email << std::endl;
|
||||
params << "Expire-Date: 0"<< std::endl;
|
||||
params << "</GnupgKeyParms>"<< std::endl;
|
||||
|
||||
return params.str();
|
||||
}
|
||||
#endif
|
||||
|
||||
static std::string setKeyPairParams(bool useRsa, unsigned int blen,
|
||||
std::string name, std::string comment, std::string email,
|
||||
std::string inPassphrase)
|
||||
@ -2357,16 +2271,25 @@ bool AuthGPGimpl::saveList(bool& cleanup, std::list<RsItem*>& lst)
|
||||
// Now save config for network digging strategies
|
||||
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ;
|
||||
std::map<std::string, bool>::iterator mapIt;
|
||||
for (mapIt = mAcceptToConnectMap.begin(); mapIt != mAcceptToConnectMap.end(); mapIt++) {
|
||||
if (mapIt->first == mOwnGpgId) {
|
||||
for (mapIt = mAcceptToConnectMap.begin(); mapIt != mAcceptToConnectMap.end(); mapIt++)
|
||||
{
|
||||
// skip our own id.
|
||||
if (mapIt->first == mOwnGpgId)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// skip if we dont accept them.
|
||||
if (!(mapIt->second))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
RsTlvKeyValue kv;
|
||||
kv.key = mapIt->first;
|
||||
#ifdef GPG_DEBUG
|
||||
std::cerr << "AuthGPGimpl::saveList() called (mapIt->second) : " << (mapIt->second) << std::endl ;
|
||||
#endif
|
||||
kv.value = (mapIt->second)?"TRUE":"FALSE" ;
|
||||
kv.value = "TRUE";
|
||||
vitem->tlvkvs.pairs.push_back(kv) ;
|
||||
}
|
||||
lst.push_back(vitem);
|
||||
@ -2385,10 +2308,11 @@ bool AuthGPGimpl::loadList(std::list<RsItem*>& load)
|
||||
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
|
||||
/* load the list of accepted gpg keys */
|
||||
std::list<RsItem *>::iterator it;
|
||||
for(it = load.begin(); it != load.end(); it++) {
|
||||
for(it = load.begin(); it != load.end(); it++)
|
||||
{
|
||||
RsConfigKeyValueSet *vitem = dynamic_cast<RsConfigKeyValueSet *>(*it);
|
||||
|
||||
if(vitem) {
|
||||
if(vitem)
|
||||
{
|
||||
#ifdef GPG_DEBUG
|
||||
std::cerr << "AuthGPGimpl::loadList() General Variable Config Item:" << std::endl;
|
||||
vitem->print(std::cerr, 10);
|
||||
@ -2396,18 +2320,22 @@ bool AuthGPGimpl::loadList(std::list<RsItem*>& load)
|
||||
#endif
|
||||
|
||||
std::list<RsTlvKeyValue>::iterator kit;
|
||||
for(kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); kit++) {
|
||||
if (kit->key == mOwnGpgId) {
|
||||
for(kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); kit++)
|
||||
{
|
||||
if (kit->key == mOwnGpgId)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
mAcceptToConnectMap[kit->key] = (kit->value == "TRUE");
|
||||
//set the gpg key
|
||||
|
||||
/* only allowed in the map if the gpg certificate exists */
|
||||
certmap::iterator it;
|
||||
if (mKeyList.end() != (it = mKeyList.find(kit->key))) {
|
||||
if (mKeyList.end() != (it = mKeyList.find(kit->key)))
|
||||
{
|
||||
#ifdef GPG_DEBUG
|
||||
std::cerr << "AuthGPGimpl::loadList() setting accept to : " << (kit->value == "TRUE");
|
||||
std::cerr << " for gpg key id : " << kit->key << std::endl;
|
||||
#endif
|
||||
mAcceptToConnectMap[kit->key] = (kit->value == "TRUE");
|
||||
it->second.accept_connection = (kit->value == "TRUE");
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/evp.h>
|
||||
#include "util/rsthreads.h"
|
||||
#include "retroshare/rspeers.h"
|
||||
//#include "retroshare/rspeers.h"
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <set>
|
||||
@ -52,6 +52,8 @@
|
||||
|
||||
#define MAX_GPG_SIGNATURE_SIZE 4096
|
||||
|
||||
class RsPeerDetails;
|
||||
|
||||
/*!
|
||||
* gpgcert is the identifier for a person.
|
||||
* It is a wrapper class for a GPGme OpenPGP certificate.
|
||||
@ -225,7 +227,9 @@ virtual std::string SaveCertificateToString(const std::string &id,bool include_s
|
||||
* done in gpgroot already.
|
||||
*
|
||||
****/
|
||||
virtual bool setAcceptToConnectGPGCertificate(const std::string &gpg_id, bool acceptance) = 0; //don't act on the gpg key, use a seperate set
|
||||
|
||||
virtual bool AllowConnection(const std::string &gpg_id, bool accept) = 0;
|
||||
|
||||
virtual bool SignCertificateLevel0(const std::string &id) = 0;
|
||||
virtual bool RevokeCertificate(const std::string &id) = 0; /* Particularly hard - leave for later */
|
||||
//virtual bool TrustCertificateNone(std::string id) = 0;
|
||||
@ -345,7 +349,8 @@ virtual std::string SaveCertificateToString(const std::string &id,bool include_s
|
||||
* done in gpgroot already.
|
||||
*
|
||||
****/
|
||||
virtual bool setAcceptToConnectGPGCertificate(const std::string &gpg_id, bool acceptance); //don't act on the gpg key, use a seperate set
|
||||
virtual bool AllowConnection(const std::string &gpg_id, bool accept);
|
||||
|
||||
virtual bool SignCertificateLevel0(const std::string &id);
|
||||
virtual bool RevokeCertificate(const std::string &id); /* Particularly hard - leave for later */
|
||||
|
||||
|
@ -37,6 +37,8 @@
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
#include "util/rsdir.h"
|
||||
|
||||
#include "retroshare/rspeers.h" // for RsPeerDetails structure
|
||||
|
||||
/******************** notify of new Cert **************************/
|
||||
#include "pqinotify.h"
|
||||
|
||||
|
@ -49,7 +49,6 @@
|
||||
|
||||
#include "pqi/pqi_base.h"
|
||||
#include "pqi/pqinetwork.h"
|
||||
//#include "rsiface/rspeers.h"
|
||||
#include "pqi/p3cfgmgr.h"
|
||||
|
||||
typedef std::string SSL_id;
|
||||
|
@ -24,7 +24,7 @@
|
||||
*/
|
||||
|
||||
#include "util/rsdir.h"
|
||||
#include "retroshare/rspeers.h"
|
||||
//#include "retroshare/rspeers.h"
|
||||
#include "pqi/p3cfgmgr.h"
|
||||
#include "pqi/authssl.h"
|
||||
#include "pqi/pqibin.h"
|
||||
|
@ -237,6 +237,12 @@ void p3LinkMgrIMPL::getFriendList(std::list<std::string> &ssl_peers)
|
||||
|
||||
}
|
||||
|
||||
bool p3LinkMgrIMPL::getPeerName(const std::string &ssl_id, std::string &name)
|
||||
{
|
||||
return mPeerMgr->getPeerName(ssl_id, name);
|
||||
}
|
||||
|
||||
|
||||
int p3LinkMgrIMPL::getFriendCount()
|
||||
{
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
@ -169,6 +169,7 @@ virtual ~p3LinkMgr() { return; }
|
||||
virtual const std::string getOwnId() = 0;
|
||||
virtual bool isOnline(const std::string &ssl_id) = 0;
|
||||
virtual void getOnlineList(std::list<std::string> &ssl_peers) = 0;
|
||||
virtual bool getPeerName(const std::string &ssl_id, std::string &name) = 0;
|
||||
|
||||
/**************** handle monitors *****************/
|
||||
virtual void addMonitor(pqiMonitor *mon) = 0;
|
||||
@ -224,6 +225,7 @@ class p3LinkMgrIMPL: public p3LinkMgr
|
||||
virtual const std::string getOwnId();
|
||||
virtual bool isOnline(const std::string &ssl_id);
|
||||
virtual void getOnlineList(std::list<std::string> &ssl_peers);
|
||||
virtual bool getPeerName(const std::string &ssl_id, std::string &name);
|
||||
|
||||
|
||||
/**************** handle monitors *****************/
|
||||
|
@ -882,6 +882,8 @@ void p3NetMgrIMPL::netExtCheck()
|
||||
|
||||
if (netSetupDone)
|
||||
{
|
||||
std::cerr << "p3NetMgrIMPL::netExtCheck() netSetupDone" << std::endl;
|
||||
|
||||
/* Setup NetStateBox with this info */
|
||||
updateNetStateBox_startup();
|
||||
|
||||
|
@ -42,7 +42,10 @@ const int p3peermgrzone = 9531;
|
||||
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
#include "pqi/pqinotify.h"
|
||||
#include "retroshare/rsiface.h"
|
||||
|
||||
#include "retroshare/rsiface.h" // Needed for rsicontrol (should remove this dependancy)
|
||||
#include "retroshare/rspeers.h" // Needed for Group Parameters.
|
||||
|
||||
|
||||
#include <sstream>
|
||||
|
||||
@ -110,6 +113,7 @@ p3PeerMgrIMPL::p3PeerMgrIMPL()
|
||||
mOwnState.name = AuthGPG::getAuthGPG()->getGPGOwnName();
|
||||
mOwnState.location = AuthSSL::getAuthSSL()->getOwnLocation();
|
||||
mOwnState.netMode = RS_NET_MODE_UPNP; // Default to UPNP.
|
||||
mOwnState.visState = 0;
|
||||
|
||||
lastGroupId = 1;
|
||||
|
||||
@ -156,11 +160,14 @@ void p3PeerMgrIMPL::setOwnVisState(uint32_t visState)
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
std::ostringstream out;
|
||||
out << "p3PeerMgr::setOwnVisState()";
|
||||
out << "Existing vis: " << mOwnState.visState;
|
||||
out << "Input vis: " << visState;
|
||||
rslog(RSL_WARNING, p3peermgrzone, out.str());
|
||||
|
||||
#ifdef PEER_DEBUG
|
||||
std::cerr << "p3PeerMgrIMPL::setOwnVisState()";
|
||||
std::cerr << "Existing vis: " << mOwnState.visState;
|
||||
std::cerr << "Input vis: " << visState;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << out.str() << std::endl;
|
||||
#endif
|
||||
|
||||
mOwnState.visState = visState;
|
||||
@ -182,13 +189,13 @@ void p3PeerMgrIMPL::tick()
|
||||
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
if(now > last_friends_check + INTERVAL_BETWEEN_LOCATION_CLEANING && rsPeers != NULL)
|
||||
if(now - last_friends_check > INTERVAL_BETWEEN_LOCATION_CLEANING)
|
||||
{
|
||||
std::cerr << "p3PeerMgrIMPL::tick(): cleaning unused locations." << std::endl ;
|
||||
|
||||
rslog(RSL_WARNING, p3peermgrzone, "p3PeerMgr::tick() cleanUnusedLocations()");
|
||||
rslog(RSL_WARNING, p3peermgrzone, "p3PeerMgr::tick() removeUnusedLocations()");
|
||||
|
||||
rsPeers->cleanUnusedLocations() ;
|
||||
removeUnusedLocations() ;
|
||||
last_friends_check = now ;
|
||||
}
|
||||
}
|
||||
@ -225,6 +232,23 @@ bool p3PeerMgrIMPL::isFriend(const std::string &id)
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool p3PeerMgrIMPL::getPeerName(const std::string &ssl_id, std::string &name)
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
/* check for existing */
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
it = mFriendList.find(ssl_id);
|
||||
if (it == mFriendList.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
name = it->second.name + " (" + it->second.location + ")";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool p3PeerMgrIMPL::getFriendNetStatus(const std::string &id, peerState &state)
|
||||
{
|
||||
@ -998,6 +1022,14 @@ bool p3PeerMgrIMPL::setLocation(const std::string &id, const std::string &loc
|
||||
|
||||
bool p3PeerMgrIMPL::setVisState(const std::string &id, uint32_t visState)
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "p3PeerMgr::setVisState(";
|
||||
out << id;
|
||||
out << ", " << visState << ")";
|
||||
rslog(RSL_WARNING, p3peermgrzone, out.str());
|
||||
}
|
||||
|
||||
if (id == AuthSSL::getAuthSSL()->OwnId())
|
||||
{
|
||||
setOwnVisState(visState);
|
||||
@ -1630,3 +1662,118 @@ bool p3PeerMgrIMPL::assignPeersToGroup(const std::string &groupId, const std::li
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
**********************************************************************
|
||||
******************** Stuff moved from p3peers ************************
|
||||
**********************************************************************
|
||||
**********************************************************************/
|
||||
|
||||
bool p3PeerMgrIMPL::removeAllFriendLocations(const std::string &gpgid)
|
||||
{
|
||||
std::list<std::string> sslIds;
|
||||
if (!getAssociatedPeers(gpgid, sslIds))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::list<std::string>::iterator it;
|
||||
for(it = sslIds.begin(); it != sslIds.end(); it++)
|
||||
{
|
||||
removeFriend(*it);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool p3PeerMgrIMPL::getAssociatedPeers(const std::string &gpg_id, std::list<std::string> &ids)
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3PeerMgr::getAssociatedPeers() for id : " << gpg_id << std::endl;
|
||||
#endif
|
||||
|
||||
int count = 0;
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
for(it = mFriendList.begin(); it != mFriendList.end(); it++)
|
||||
{
|
||||
if (it->second.gpg_id == gpg_id)
|
||||
{
|
||||
count++;
|
||||
ids.push_back(it->first);
|
||||
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3PeerMgr::getAssociatedPeers() found ssl id : " << it->first << std::endl;
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return (count > 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* This only removes SSL certs, that are old... Can end up with no Certs per GPG Id
|
||||
* We are removing the concept of a "DummyId" - There is no need for it.
|
||||
*/
|
||||
|
||||
bool isDummyFriend(std::string id)
|
||||
{
|
||||
bool ret = (id.substr(0,5) == "dummy");
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define VERY_OLD_PEER (30 * 24 * 3600) // 30 days.
|
||||
|
||||
bool p3PeerMgrIMPL::removeUnusedLocations()
|
||||
{
|
||||
std::list<std::string> toRemove;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3PeerMgr::removeUnusedLocations()" << std::endl;
|
||||
#endif
|
||||
|
||||
time_t now = time(NULL);
|
||||
|
||||
std::map<std::string, peerState>::iterator it;
|
||||
for(it = mFriendList.begin(); it != mFriendList.end(); it++)
|
||||
{
|
||||
if (now - it->second.lastcontact > VERY_OLD_PEER)
|
||||
{
|
||||
toRemove.push_back(it->first);
|
||||
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3PeerMgr::removeUnusedLocations() removing Old SSL Id: " << it->first << std::endl;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
if (isDummyFriend(it->first))
|
||||
{
|
||||
toRemove.push_back(it->first);
|
||||
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3PeerMgr::removeUnusedLocations() removing Dummy Id: " << it->first << std::endl;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
std::list<std::string>::iterator it;
|
||||
|
||||
for(it = toRemove.begin(); it != toRemove.end(); it++)
|
||||
{
|
||||
removeFriend(*it);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -127,6 +127,8 @@ virtual bool removeFriend(const std::string &ssl_id) = 0;
|
||||
|
||||
virtual bool isFriend(const std::string &ssl_id) = 0;
|
||||
|
||||
virtual bool getAssociatedPeers(const std::string &gpg_id, std::list<std::string> &ids) = 0;
|
||||
virtual bool removeAllFriendLocations(const std::string &gpgid) = 0;
|
||||
|
||||
|
||||
/******************** Groups **********************/
|
||||
@ -178,6 +180,8 @@ virtual bool getOwnNetStatus(peerState &state) = 0;
|
||||
virtual bool getFriendNetStatus(const std::string &id, peerState &state) = 0;
|
||||
virtual bool getOthersNetStatus(const std::string &id, peerState &state) = 0;
|
||||
|
||||
virtual bool getPeerName(const std::string &ssl_id, std::string &name) = 0;
|
||||
|
||||
|
||||
/************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
|
||||
|
||||
@ -208,6 +212,9 @@ virtual bool removeFriend(const std::string &ssl_id);
|
||||
|
||||
virtual bool isFriend(const std::string &ssl_id);
|
||||
|
||||
virtual bool getAssociatedPeers(const std::string &gpg_id, std::list<std::string> &ids);
|
||||
virtual bool removeAllFriendLocations(const std::string &gpgid);
|
||||
|
||||
|
||||
/******************** Groups **********************/
|
||||
/* This is solely used by p3peers - makes sense */
|
||||
@ -257,6 +264,8 @@ virtual bool getOwnNetStatus(peerState &state);
|
||||
virtual bool getFriendNetStatus(const std::string &id, peerState &state);
|
||||
virtual bool getOthersNetStatus(const std::string &id, peerState &state);
|
||||
|
||||
virtual bool getPeerName(const std::string &ssl_id, std::string &name);
|
||||
|
||||
|
||||
/************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
|
||||
|
||||
@ -282,8 +291,13 @@ int getConnectAddresses(const std::string &id,
|
||||
struct sockaddr_in &lAddr, struct sockaddr_in &eAddr,
|
||||
pqiIpAddrSet &histAddrs, std::string &dyndns);
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
/* Internal Functions */
|
||||
|
||||
bool removeUnusedLocations();
|
||||
|
||||
void printPeerLists(std::ostream &out);
|
||||
|
||||
protected:
|
||||
|
@ -493,6 +493,8 @@ int pqissllistenbase::closeConnection(int fd, SSL *ssl)
|
||||
/************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
// free connection.
|
||||
SSL_free(ssl);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -186,14 +186,12 @@ virtual bool getGPGSignedList(std::list<std::string> &gpg_ids) = 0;//friend
|
||||
virtual bool getGPGValidList(std::list<std::string> &gpg_ids) = 0;
|
||||
virtual bool getGPGAllList(std::list<std::string> &gpg_ids) = 0;
|
||||
virtual bool getGPGDetails(const std::string &gpg_id, RsPeerDetails &d) = 0;
|
||||
virtual bool getSSLChildListOfGPGId(const std::string &gpg_id, std::list<std::string> &ssl_ids) = 0;
|
||||
virtual bool getAssociatedSSLIds(const std::string &gpg_id, std::list<std::string> &ids) = 0;
|
||||
|
||||
/* Add/Remove Friends */
|
||||
virtual bool addFriend(const std::string &ssl_id, const std::string &gpg_id) = 0;
|
||||
virtual bool addDummyFriend(const std::string &gpg_id) = 0; //we want to add a empty ssl friend for this gpg id
|
||||
virtual bool isDummyFriend(const std::string &ssl_id) = 0;
|
||||
virtual bool removeFriend(const std::string &ssl_or_gpg_id) = 0;
|
||||
virtual bool cleanUnusedLocations() = 0 ;
|
||||
virtual bool removeFriendLocation(const std::string &sslId) = 0;
|
||||
|
||||
/* Network Stuff */
|
||||
virtual bool connectAttempt(const std::string &ssl_id) = 0;
|
||||
@ -221,7 +219,7 @@ virtual bool cleanCertificate(const std::string &certstr, std::string &cleanCert
|
||||
virtual bool saveCertificateToFile(const std::string &id, const std::string &fname) = 0;
|
||||
virtual std::string saveCertificateToString(const std::string &id) = 0;
|
||||
|
||||
virtual bool setAcceptToConnectGPGCertificate(const std::string &gpg_id, bool acceptance) = 0;
|
||||
//virtual bool setAcceptToConnectGPGCertificate(const std::string &gpg_id, bool acceptance) = 0;
|
||||
virtual bool signGPGCertificate(const std::string &gpg_id) = 0;
|
||||
virtual bool trustGPGCertificate(const std::string &gpg_id, uint32_t trustlvl) = 0;
|
||||
|
||||
|
@ -250,6 +250,199 @@ bool p3Peers::isFriend(const std::string &ssl_id)
|
||||
}
|
||||
|
||||
|
||||
/* There are too many dependancies of this function
|
||||
* to shift it immeidately
|
||||
*/
|
||||
|
||||
bool p3Peers::getPeerDetails(const std::string &id, RsPeerDetails &d)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::getPeerDetails() called for id : " << id << std::endl;
|
||||
#endif
|
||||
|
||||
// NOW Only for SSL Details.
|
||||
|
||||
std::string sOwnId = AuthSSL::getAuthSSL()->OwnId();
|
||||
peerState ps;
|
||||
|
||||
if (id == sOwnId)
|
||||
{
|
||||
mPeerMgr->getOwnNetStatus(ps);
|
||||
ps.gpg_id = AuthGPG::getAuthGPG()->getGPGOwnId();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!mPeerMgr->getFriendNetStatus(id, ps))
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::getPeerDetails() ERROR not an SSL Id: " << id << std::endl;
|
||||
#endif
|
||||
d.isOnlyGPGdetail = false;
|
||||
return getGPGDetails(id, d);
|
||||
}
|
||||
}
|
||||
|
||||
/* get from gpg (first), to fill in the sign and trust details */
|
||||
/* don't retrun now, we've got fill in the ssl and connection info */
|
||||
getGPGDetails(ps.gpg_id, d);
|
||||
d.isOnlyGPGdetail = false;
|
||||
|
||||
//get the ssl details
|
||||
d.id = id;
|
||||
d.location = ps.location;
|
||||
|
||||
/* generate */
|
||||
d.authcode = "AUTHCODE";
|
||||
|
||||
/* fill from pcs */
|
||||
|
||||
d.localAddr = rs_inet_ntoa(ps.localaddr.sin_addr);
|
||||
d.localPort = ntohs(ps.localaddr.sin_port);
|
||||
d.extAddr = rs_inet_ntoa(ps.serveraddr.sin_addr);
|
||||
d.extPort = ntohs(ps.serveraddr.sin_port);
|
||||
d.dyndns = ps.dyndns;
|
||||
d.lastConnect = ps.lastcontact;
|
||||
d.connectPeriod = 0;
|
||||
|
||||
|
||||
std::list<pqiIpAddress>::iterator it;
|
||||
for(it = ps.ipAddrs.mLocal.mAddrs.begin();
|
||||
it != ps.ipAddrs.mLocal.mAddrs.end(); it++)
|
||||
{
|
||||
std::ostringstream toto;
|
||||
toto << ntohs(it->mAddr.sin_port) << " " << (time(NULL) - it->mSeenTime) << " sec";
|
||||
d.ipAddressList.push_back("L:" + std::string(rs_inet_ntoa(it->mAddr.sin_addr)) + ":" + toto.str());
|
||||
}
|
||||
for(it = ps.ipAddrs.mExt.mAddrs.begin();
|
||||
it != ps.ipAddrs.mExt.mAddrs.end(); it++)
|
||||
{
|
||||
std::ostringstream toto;
|
||||
toto << ntohs(it->mAddr.sin_port) << " " << (time(NULL) - it->mSeenTime) << " sec";
|
||||
d.ipAddressList.push_back("E:" + std::string(rs_inet_ntoa(it->mAddr.sin_addr)) + ":" + toto.str());
|
||||
}
|
||||
|
||||
|
||||
switch(ps.netMode & RS_NET_MODE_ACTUAL)
|
||||
{
|
||||
case RS_NET_MODE_EXT:
|
||||
d.netMode = RS_NETMODE_EXT;
|
||||
break;
|
||||
case RS_NET_MODE_UPNP:
|
||||
d.netMode = RS_NETMODE_UPNP;
|
||||
break;
|
||||
case RS_NET_MODE_UDP:
|
||||
d.netMode = RS_NETMODE_UDP;
|
||||
break;
|
||||
case RS_NET_MODE_UNREACHABLE:
|
||||
case RS_NET_MODE_UNKNOWN:
|
||||
default:
|
||||
d.netMode = RS_NETMODE_UNREACHABLE;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (ps.netMode & RS_NET_MODE_TRY_EXT)
|
||||
{
|
||||
d.tryNetMode = RS_NETMODE_EXT;
|
||||
}
|
||||
else if (ps.netMode & RS_NET_MODE_TRY_UPNP)
|
||||
{
|
||||
d.tryNetMode = RS_NETMODE_UPNP;
|
||||
}
|
||||
else
|
||||
{
|
||||
d.tryNetMode = RS_NETMODE_UDP;
|
||||
}
|
||||
|
||||
d.visState = 0;
|
||||
if (!(ps.visState & RS_VIS_STATE_NODISC))
|
||||
{
|
||||
d.visState |= RS_VS_DISC_ON;
|
||||
}
|
||||
|
||||
if (!(ps.visState & RS_VIS_STATE_NODHT))
|
||||
{
|
||||
d.visState |= RS_VS_DHT_ON;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* Translate */
|
||||
peerConnectState pcs;
|
||||
if (!mLinkMgr->getFriendNetStatus(id, pcs))
|
||||
{
|
||||
std::cerr << "p3Peers::getPeerDetails() ERROR No Link Information : " << id << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::getPeerDetails() got a SSL id and is returning SSL and GPG details for id : " << id << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
d.state = 0;
|
||||
if (pcs.state & RS_PEER_S_FRIEND)
|
||||
d.state |= RS_PEER_STATE_FRIEND;
|
||||
if (pcs.state & RS_PEER_S_ONLINE)
|
||||
d.state |= RS_PEER_STATE_ONLINE;
|
||||
if (pcs.state & RS_PEER_S_CONNECTED)
|
||||
d.state |= RS_PEER_STATE_CONNECTED;
|
||||
if (pcs.state & RS_PEER_S_UNREACHABLE)
|
||||
d.state |= RS_PEER_STATE_UNREACHABLE;
|
||||
|
||||
|
||||
|
||||
/* Finally determine AutoConnect Status */
|
||||
d.foundDHT = pcs.dht.found;
|
||||
|
||||
d.connectState = 0;
|
||||
d.connectStateString.clear();
|
||||
|
||||
|
||||
if (pcs.inConnAttempt)
|
||||
{
|
||||
if (pcs.currentConnAddrAttempt.type & RS_NET_CONN_TUNNEL) {
|
||||
d.connectState = RS_PEER_CONNECTSTATE_TRYING_TUNNEL;
|
||||
} else if (pcs.currentConnAddrAttempt.type & RS_NET_CONN_TCP_ALL) {
|
||||
d.connectState = RS_PEER_CONNECTSTATE_TRYING_TCP;
|
||||
|
||||
std::ostringstream str;
|
||||
str << rs_inet_ntoa(pcs.currentConnAddrAttempt.addr.sin_addr) << ":" << ntohs(pcs.currentConnAddrAttempt.addr.sin_port);
|
||||
d.connectStateString = str.str();
|
||||
} else if (pcs.currentConnAddrAttempt.type & RS_NET_CONN_UDP_ALL) {
|
||||
d.connectState = RS_PEER_CONNECTSTATE_TRYING_UDP;
|
||||
|
||||
std::ostringstream str;
|
||||
str << rs_inet_ntoa(pcs.currentConnAddrAttempt.addr.sin_addr) << ":" << ntohs(pcs.currentConnAddrAttempt.addr.sin_port);
|
||||
d.connectStateString = str.str();
|
||||
}
|
||||
}
|
||||
else if (pcs.state & RS_PEER_S_CONNECTED)
|
||||
{
|
||||
if (pcs.connecttype == RS_NET_CONN_TCP_ALL)
|
||||
{
|
||||
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_TCP;
|
||||
}
|
||||
else if (pcs.connecttype == RS_NET_CONN_UDP_ALL)
|
||||
{
|
||||
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_UDP;
|
||||
}
|
||||
else if (pcs.connecttype == RS_NET_CONN_TUNNEL)
|
||||
{
|
||||
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_TUNNEL;
|
||||
}
|
||||
else
|
||||
{
|
||||
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
bool p3Peers::getPeerDetails(const std::string &id, RsPeerDetails &d)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
@ -433,6 +626,7 @@ bool p3Peers::getPeerDetails(const std::string &id, RsPeerDetails &d)
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
std::string p3Peers::getGPGName(const std::string &gpg_id)
|
||||
@ -453,20 +647,23 @@ std::string p3Peers::getPeerName(const std::string &ssl_or_gpg_id)
|
||||
std::cerr << "p3Peers::getPeerName() " << ssl_or_gpg_id << std::endl;
|
||||
#endif
|
||||
std::string name;
|
||||
if (ssl_or_gpg_id == AuthSSL::getAuthSSL()->OwnId()) {
|
||||
if (ssl_or_gpg_id == AuthSSL::getAuthSSL()->OwnId())
|
||||
{
|
||||
return AuthGPG::getAuthGPG()->getGPGOwnName();
|
||||
}
|
||||
peerState pcs;
|
||||
if (mPeerMgr->getFriendNetStatus(ssl_or_gpg_id, pcs)) {
|
||||
|
||||
if (mPeerMgr->getPeerName(ssl_or_gpg_id, name))
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::getPeerName() got a ssl id. Name is : " << pcs.name << std::endl;
|
||||
std::cerr << "p3Peers::getPeerName() got a ssl id. Name is : " << name << std::endl;
|
||||
#endif
|
||||
return pcs.name;
|
||||
return name;
|
||||
}
|
||||
|
||||
return AuthGPG::getAuthGPG()->getGPGName(ssl_or_gpg_id);
|
||||
}
|
||||
|
||||
|
||||
bool p3Peers::getGPGAllList(std::list<std::string> &ids)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
@ -509,107 +706,16 @@ bool p3Peers::getGPGAcceptedList(std::list<std::string> &ids)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3Peers::getSSLChildListOfGPGId(const std::string &gpg_id, std::list<std::string> &ids)
|
||||
|
||||
bool p3Peers::getAssociatedSSLIds(const std::string &gpg_id, std::list<std::string> &ids)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::getSSLChildListOfGPGId() for id : " << gpg_id << std::endl;
|
||||
std::cerr << "p3Peers::getAssociatedSSLIds() for id : " << gpg_id << std::endl;
|
||||
#endif
|
||||
ids.clear();
|
||||
if (gpg_id == "" ) {
|
||||
return false;
|
||||
}
|
||||
//let's roll throush the friends
|
||||
std::list<std::string> friendsIds;
|
||||
mLinkMgr->getFriendList(friendsIds);
|
||||
peerState pcs;
|
||||
for (std::list<std::string>::iterator it = friendsIds.begin(); it != friendsIds.end(); it++)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::getSSLChildListOfGPGId() iterating over friends id : " << *it << std::endl;
|
||||
#endif
|
||||
if (mPeerMgr->getFriendNetStatus(*it, pcs) && pcs.gpg_id == gpg_id) {
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::getSSLChildListOfGPGId() adding ssl id : " << pcs.id << std::endl;
|
||||
#endif
|
||||
ids.push_back(pcs.id);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
return mPeerMgr->getAssociatedPeers(gpg_id, ids);
|
||||
}
|
||||
|
||||
bool p3Peers::cleanUnusedLocations()
|
||||
{
|
||||
// Obtain all current locations of each GPG friend.
|
||||
//
|
||||
std::map<std::string,std::list<peerState> > friends_info ;
|
||||
std::list<std::string> friendSSLIds ;
|
||||
|
||||
mLinkMgr->getFriendList(friendSSLIds);
|
||||
|
||||
for(std::list<std::string>::const_iterator it(friendSSLIds.begin());it!=friendSSLIds.end();++it)
|
||||
{
|
||||
peerState pcs;
|
||||
|
||||
if(mPeerMgr->getFriendNetStatus(*it, pcs))
|
||||
friends_info[pcs.gpg_id].push_back(pcs) ;
|
||||
}
|
||||
|
||||
// Now sort them out
|
||||
//
|
||||
|
||||
std::cerr << "Examining Old/Unused locations." << std::endl ;
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
std::list<std::string> locations_to_remove ;
|
||||
|
||||
for(std::map<std::string,std::list<peerState> >::iterator it(friends_info.begin());it!=friends_info.end();++it)
|
||||
{
|
||||
std::list<peerState>& locations_list(it->second) ;
|
||||
|
||||
int size = locations_list.size() ;
|
||||
|
||||
std::cerr << " GPG id: " << it->first << std::endl ;
|
||||
|
||||
for(std::list<peerState>::const_iterator itloc(locations_list.begin());itloc!=locations_list.end();++itloc)
|
||||
std::cerr << " Location " << (*itloc).id << ", last contact " << now - (*itloc).lastcontact << " seconds ago" << std::endl ;
|
||||
|
||||
// Remove any location that is dummy. Update the list, such that we only look into non dummy friends later.
|
||||
//
|
||||
for(std::list<peerState>::iterator itloc(locations_list.begin());itloc!=locations_list.end();)
|
||||
if(size > 1 && isDummyFriend((*itloc).id))
|
||||
{
|
||||
locations_to_remove.push_back((*itloc).id) ;
|
||||
--size ;
|
||||
|
||||
std::cerr << " Removing dummy location: " << (*itloc).id << std::endl ;
|
||||
|
||||
std::list<peerState>::iterator tmp(itloc) ;
|
||||
++tmp ;
|
||||
locations_list.erase(itloc) ;
|
||||
itloc=tmp ;
|
||||
}
|
||||
else
|
||||
++itloc ;
|
||||
|
||||
for(std::list<peerState>::const_iterator itloc(locations_list.begin());itloc!=locations_list.end();++itloc)
|
||||
if(size > 1 && now > (*itloc).lastcontact + MAX_TIME_KEEP_LOCATION_WITHOUT_CONTACT)
|
||||
{
|
||||
locations_to_remove.push_back((*itloc).id) ;
|
||||
--size ;
|
||||
std::cerr << " Removing unused location: " << (*itloc).id << std::endl ;
|
||||
}
|
||||
}
|
||||
|
||||
std::cerr << "Now removing unused locations:" << std::endl ;
|
||||
|
||||
for(std::list<std::string>::const_iterator it(locations_to_remove.begin());it!=locations_to_remove.end();++it)
|
||||
{
|
||||
std::cerr << " Removing unused friend location " << *it << std::endl ;
|
||||
removeFriend(*it) ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool p3Peers::getGPGDetails(const std::string &id, RsPeerDetails &d)
|
||||
{
|
||||
@ -656,74 +762,117 @@ std::string p3Peers::getGPGId(const std::string &sslid_or_gpgid)
|
||||
}
|
||||
|
||||
|
||||
/* These Functions are now the only way to authorize a new gpg user...
|
||||
* if we are passed a ssl_id, then use it... otherwise just auth gpg_id
|
||||
*/
|
||||
|
||||
/* Add/Remove Friends */
|
||||
bool p3Peers::addFriend(const std::string &id, const std::string &gpg_id)
|
||||
bool p3Peers::addFriend(const std::string &ssl_id, const std::string &gpg_id)
|
||||
{
|
||||
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::addFriend() with : id : " << id << "; gpg_id : " << gpg_id << std::endl;
|
||||
#endif
|
||||
if (id == gpg_id || id == "") {
|
||||
return addDummyFriend(gpg_id);
|
||||
} else {
|
||||
return mPeerMgr->addFriend(id, gpg_id);
|
||||
}
|
||||
}
|
||||
|
||||
bool p3Peers::addDummyFriend(const std::string &gpg_id)
|
||||
if (AuthGPG::getAuthGPG()->isGPGId(gpg_id))
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::addDummyFriend() called" << std::endl;
|
||||
std::cerr << "p3Peers::addFriend() Authorising GPG Id: " << gpg_id << std::endl;
|
||||
#endif
|
||||
std::string dummy_ssl_id = "dummy"+ gpg_id;
|
||||
//check if this gpg_id already got a dummy friend
|
||||
if (!mPeerMgr->isFriend(dummy_ssl_id)) {
|
||||
return mPeerMgr->addFriend(dummy_ssl_id, gpg_id);
|
||||
} else {
|
||||
if (AuthGPG::getAuthGPG()->AllowConnection(gpg_id, true))
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::addDummyFriend() dummy friend already exists for gpg_id : " << gpg_id << std::endl;
|
||||
std::cerr << "p3Peers::addFriend() Authorization OK." << std::endl;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::addFriend() Authorization FAILED." << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool p3Peers::isDummyFriend(const std::string &ssl_id) {
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::isDummyFriend() called" << std::endl;
|
||||
#endif
|
||||
RsPeerDetails details;
|
||||
bool ret = false;
|
||||
if (getPeerDetails(ssl_id, details)) {
|
||||
ret = (details.id == ("dummy" + details.gpg_id));
|
||||
} else {
|
||||
ret = (ssl_id.substr(0,5) == "dummy");
|
||||
}
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::isDummyFriend() return : " << ret << std::endl;
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool p3Peers::removeFriend(const std::string &ssl_or_gpgid)
|
||||
else
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::removeFriend() " << ssl_or_gpgid << std::endl;
|
||||
#endif
|
||||
if (ssl_or_gpgid == AuthGPG::getAuthGPG()->getGPGOwnId()) {
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::removeFriend() fail : we're not going to remove our own GPG id." << std::endl;
|
||||
std::cerr << "p3Peers::addFriend() Bad gpg_id : " << gpg_id << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
//will remove if it's a gpg id
|
||||
AuthGPG::getAuthGPG()->setAcceptToConnectGPGCertificate(ssl_or_gpgid, false);
|
||||
|
||||
if (ssl_id == gpg_id || ssl_id == "")
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::addFriend() WARNING id is NULL or gpgId" << std::endl;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
/* otherwise - we install as ssl_id. */
|
||||
return mPeerMgr->addFriend(ssl_id, gpg_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool p3Peers::removeFriendLocation(const std::string &sslId)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::removeFriendLocation() " << sslId << std::endl;
|
||||
#endif
|
||||
//will remove if it's a ssl id
|
||||
mPeerMgr->removeFriend(ssl_or_gpgid);
|
||||
mPeerMgr->removeFriend(sslId);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool p3Peers::removeFriend(const std::string &gpgId)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::removeFriend() " << gpgId << std::endl;
|
||||
#endif
|
||||
if (gpgId == AuthGPG::getAuthGPG()->getGPGOwnId()) {
|
||||
std::cerr << "p3Peers::removeFriend() ERROR we're not going to remove our own GPG id." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (AuthGPG::getAuthGPG()->isGPGId(gpgId))
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::removeFriend() Removing GPG Id: " << gpgId << std::endl;
|
||||
#endif
|
||||
if (AuthGPG::getAuthGPG()->AllowConnection(gpgId, false))
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::removeFriend() OK." << std::endl;
|
||||
#endif
|
||||
mPeerMgr->removeAllFriendLocations(gpgId);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::removeFriend() FAILED." << std::endl;
|
||||
#endif
|
||||
mPeerMgr->removeAllFriendLocations(gpgId);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::removeFriend() Not GPG Id: " << gpg_id << std::endl;
|
||||
#endif
|
||||
return removeFriendLocation(gpgId);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Network Stuff */
|
||||
bool p3Peers::connectAttempt(const std::string &id)
|
||||
{
|
||||
@ -1187,27 +1336,10 @@ bool p3Peers::signGPGCertificate(const std::string &id)
|
||||
#endif
|
||||
|
||||
|
||||
AuthGPG::getAuthGPG()->setAcceptToConnectGPGCertificate(id, true);
|
||||
AuthGPG::getAuthGPG()->AllowConnection(id, true);
|
||||
return AuthGPG::getAuthGPG()->SignCertificateLevel0(id);
|
||||
}
|
||||
|
||||
bool p3Peers::setAcceptToConnectGPGCertificate(const std::string &gpg_id, bool acceptance)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::setAcceptToConnectGPGCertificate() called with gpg_id : " << gpg_id << ", acceptance : " << acceptance << std::endl;
|
||||
#endif
|
||||
|
||||
if (gpg_id != "" && acceptance == false) {
|
||||
//remove the friends from the connect manager
|
||||
std::list<std::string> sslFriends;
|
||||
this->getSSLChildListOfGPGId(gpg_id, sslFriends);
|
||||
for (std::list<std::string>::iterator it = sslFriends.begin(); it != sslFriends.end(); it++) {
|
||||
mPeerMgr->removeFriend(*it);
|
||||
}
|
||||
return AuthGPG::getAuthGPG()->setAcceptToConnectGPGCertificate(gpg_id, acceptance);
|
||||
}
|
||||
return AuthGPG::getAuthGPG()->setAcceptToConnectGPGCertificate(gpg_id, acceptance);
|
||||
}
|
||||
|
||||
bool p3Peers::trustGPGCertificate(const std::string &id, uint32_t trustlvl)
|
||||
{
|
||||
|
@ -46,6 +46,8 @@ virtual bool OthersChanged();
|
||||
/* Peer Details (Net & Auth) */
|
||||
virtual std::string getOwnId();
|
||||
|
||||
|
||||
|
||||
virtual bool getOnlineList(std::list<std::string> &ids);
|
||||
virtual bool getFriendList(std::list<std::string> &ids);
|
||||
//virtual bool getOthersList(std::list<std::string> &ids);
|
||||
@ -56,7 +58,7 @@ virtual bool isFriend(const std::string &id);
|
||||
virtual bool isGPGAccepted(const std::string &gpg_id_is_friend); //
|
||||
virtual std::string getGPGName(const std::string &gpg_id);
|
||||
virtual std::string getPeerName(const std::string &ssl_or_gpg_id);
|
||||
virtual bool getPeerDetails(const std::string &id, RsPeerDetails &d);
|
||||
virtual bool getPeerDetails(const std::string &ssl_or_gpg_id, RsPeerDetails &d);
|
||||
|
||||
/* Using PGP Ids */
|
||||
virtual std::string getGPGOwnId();
|
||||
@ -66,14 +68,12 @@ virtual bool getGPGSignedList(std::list<std::string> &ids);
|
||||
virtual bool getGPGValidList(std::list<std::string> &ids);
|
||||
virtual bool getGPGAllList(std::list<std::string> &ids);
|
||||
virtual bool getGPGDetails(const std::string &id, RsPeerDetails &d);
|
||||
virtual bool getSSLChildListOfGPGId(const std::string &gpg_id, std::list<std::string> &ids);
|
||||
virtual bool getAssociatedSSLIds(const std::string &gpg_id, std::list<std::string> &ids);
|
||||
|
||||
/* Add/Remove Friends */
|
||||
virtual bool addFriend(const std::string &ssl_id, const std::string &gpg_id);
|
||||
virtual bool addDummyFriend(const std::string &gpg_id); //we want to add a empty ssl friend for this gpg id
|
||||
virtual bool isDummyFriend(const std::string &ssl_id);
|
||||
virtual bool removeFriend(const std::string &ssl_id);
|
||||
virtual bool cleanUnusedLocations() ;
|
||||
virtual bool removeFriend(const std::string &ssl_or_gpgid);
|
||||
virtual bool removeFriendLocation(const std::string &sslId);
|
||||
|
||||
/* Network Stuff */
|
||||
virtual bool connectAttempt(const std::string &id);
|
||||
@ -103,7 +103,6 @@ virtual bool cleanCertificate(const std::string &certstr, std::string &cleanCert
|
||||
virtual bool saveCertificateToFile(const std::string &id, const std::string &fname);
|
||||
virtual std::string saveCertificateToString(const std::string &id);
|
||||
|
||||
virtual bool setAcceptToConnectGPGCertificate(const std::string &gpg_id, bool acceptance);
|
||||
virtual bool signGPGCertificate(const std::string &id);
|
||||
virtual bool trustGPGCertificate(const std::string &id, uint32_t trustlvl);
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
#include "retroshare/rspeers.h"
|
||||
#include "retroshare/rspeers.h" // Needed for RsGroupInfo.
|
||||
|
||||
/***
|
||||
* #define RSSERIAL_DEBUG 1
|
||||
|
@ -25,7 +25,6 @@
|
||||
|
||||
|
||||
#include "retroshare/rsiface.h"
|
||||
#include "retroshare/rsinit.h" /* for PGPSSL flag */
|
||||
#include "retroshare/rspeers.h"
|
||||
#include "services/p3disc.h"
|
||||
|
||||
@ -74,11 +73,6 @@ const uint32_t P3DISC_FLAGS_ASK_VERSION = 0x0080;
|
||||
|
||||
//#define P3DISC_DEBUG 1
|
||||
|
||||
/*********** NOTE ***************
|
||||
*
|
||||
* Only need Mutexs for neighbours information
|
||||
*/
|
||||
|
||||
/******************************************************************************************
|
||||
****************************** NEW DISCOVERY *******************************************
|
||||
******************************************************************************************
|
||||
@ -94,7 +88,8 @@ p3disc::p3disc(p3PeerMgr *pm, p3LinkMgr *lm, pqipersongrp *pqih)
|
||||
|
||||
addSerialType(new RsDiscSerialiser());
|
||||
|
||||
lastSentHeartbeatTime = time(NULL);
|
||||
mLastSentHeartbeatTime = time(NULL);
|
||||
mDiscEnabled = true;
|
||||
|
||||
//add own version to versions map
|
||||
versions[AuthSSL::getAuthSSL()->OwnId()] = RsUtil::retroshareVersion();
|
||||
@ -109,17 +104,35 @@ p3disc::p3disc(p3PeerMgr *pm, p3LinkMgr *lm, pqipersongrp *pqih)
|
||||
int p3disc::tick()
|
||||
{
|
||||
//send a heartbeat to all connected peers
|
||||
if (time(NULL) - lastSentHeartbeatTime > HEARTBEAT_REPEAT_TIME)
|
||||
time_t hbTime;
|
||||
{
|
||||
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
||||
hbTime = mLastSentHeartbeatTime;
|
||||
}
|
||||
|
||||
if (time(NULL) - hbTime > HEARTBEAT_REPEAT_TIME)
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::tick() sending heartbeat to all peers" << std::endl;
|
||||
#endif
|
||||
lastSentHeartbeatTime = time(NULL);
|
||||
|
||||
std::list<std::string> peers;
|
||||
std::list<std::string>::const_iterator pit;
|
||||
|
||||
mLinkMgr->getOnlineList(peers);
|
||||
for (std::list<std::string>::const_iterator pit = peers.begin(); pit != peers.end(); ++pit) {
|
||||
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);
|
||||
}
|
||||
|
||||
return handleIncoming();
|
||||
@ -133,23 +146,6 @@ int p3disc::handleIncoming()
|
||||
std::cerr << "p3disc::handleIncoming()" << std::endl;
|
||||
#endif
|
||||
|
||||
// if off discard item.
|
||||
peerState detail;
|
||||
if (!mPeerMgr->getOwnNetStatus(detail) || (detail.visState & RS_VIS_STATE_NODISC))
|
||||
{
|
||||
while(NULL != (item = recvItem()))
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::handleIncoming() Deleting - Cos RemoteDisc Off!" << std::endl;
|
||||
item -> print(std::cerr);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
delete item;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nhandled = 0;
|
||||
// While messages read
|
||||
while(NULL != (item = recvItem()))
|
||||
@ -165,36 +161,25 @@ int p3disc::handleIncoming()
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
// if discovery reply then respond if haven't already.
|
||||
if (NULL != (dri = dynamic_cast<RsDiscReply *> (item))) {
|
||||
|
||||
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
/* search pending item and remove it, when already exist */
|
||||
std::list<RsDiscReply*>::iterator it;
|
||||
for (it = pendingDiscReplyInList.begin(); it != pendingDiscReplyInList.end(); it++) {
|
||||
if ((*it)->PeerId() == dri->PeerId() && (*it)->aboutId == dri->aboutId) {
|
||||
delete (*it);
|
||||
pendingDiscReplyInList.erase(it);
|
||||
break;
|
||||
if (NULL != (dri = dynamic_cast<RsDiscReply *> (item)))
|
||||
{
|
||||
recvDiscReply(dri);
|
||||
}
|
||||
}
|
||||
|
||||
// add item to list for later process
|
||||
pendingDiscReplyInList.push_back(dri); // no delete
|
||||
}
|
||||
else if (NULL != (dvi = dynamic_cast<RsDiscVersion *> (item))) {
|
||||
else if (NULL != (dvi = dynamic_cast<RsDiscVersion *> (item)))
|
||||
{
|
||||
recvPeerVersionMsg(dvi);
|
||||
nhandled++;
|
||||
delete item;
|
||||
}
|
||||
else if (NULL != (inf = dynamic_cast<RsDiscAskInfo *> (item))) /* Ping */ {
|
||||
else if (NULL != (inf = dynamic_cast<RsDiscAskInfo *> (item))) /* Ping */
|
||||
{
|
||||
recvAskInfo(inf);
|
||||
nhandled++;
|
||||
delete item;
|
||||
}
|
||||
else if (NULL != (dta = dynamic_cast<RsDiscHeartbeat *> (item))) {
|
||||
else if (NULL != (dta = dynamic_cast<RsDiscHeartbeat *> (item)))
|
||||
{
|
||||
recvHeartbeatMsg(dta);
|
||||
nhandled++ ;
|
||||
delete item;
|
||||
@ -219,6 +204,7 @@ int p3disc::handleIncoming()
|
||||
|
||||
|
||||
|
||||
|
||||
/************* from pqiMonitor *******************/
|
||||
void p3disc::statusChange(const std::list<pqipeer> &plist)
|
||||
{
|
||||
@ -268,54 +254,66 @@ void p3disc::sendAllInfoToJustConnectedPeer(const std::string &id)
|
||||
std::cerr << "p3disc::sendAllInfoToJustConnectedPeer() id: " << id << std::endl;
|
||||
#endif
|
||||
|
||||
RsPeerDetails pd;
|
||||
rsPeers->getPeerDetails(id, pd);
|
||||
|
||||
if (pd.gpg_id != rsPeers->getGPGOwnId() && (!pd.accept_connection || !pd.ownsign) )
|
||||
{
|
||||
//only send info when connection is accepted and gpg key is signed or our own key
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::sendAllInfoToJustConnectedPeer() we're not sending the info because the destination gpg key is not signed or not accepted." << std::cerr << std::endl;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
std::list<std::string> friendIds;
|
||||
std::list<std::string>::iterator friendIdsIt;
|
||||
std::list<std::string>::iterator it;
|
||||
std::set<std::string> gpgIds;
|
||||
std::set<std::string>::iterator git;
|
||||
|
||||
rsPeers->getFriendList(friendIds);
|
||||
/* 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);
|
||||
|
||||
/* send them a list of all friend's details */
|
||||
for(friendIdsIt = friendIds.begin(); friendIdsIt != friendIds.end(); friendIdsIt++) {
|
||||
for(it = friendIds.begin(); it != friendIds.end(); it++)
|
||||
{
|
||||
/* get details */
|
||||
peerState detail;
|
||||
if (!mPeerMgr->getFriendNetStatus(*friendIdsIt, 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)) {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//add own info
|
||||
//add own info, this info is sent whether discovery is enabled - or not.
|
||||
gpgIds.insert(rsPeers->getGPGOwnId());
|
||||
|
||||
{
|
||||
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
/* append gpg id's to the sending list for the id */
|
||||
|
||||
std::list<std::string> &idList = sendIdList[id];
|
||||
|
||||
std::set<std::string>::iterator gpgIdsIt;
|
||||
for (gpgIdsIt = gpgIds.begin(); gpgIdsIt != gpgIds.end(); gpgIdsIt++) {
|
||||
if (std::find(idList.begin(), idList.end(), *gpgIdsIt) == idList.end()) {
|
||||
idList.push_back(*gpgIdsIt);
|
||||
}
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -326,14 +324,46 @@ void p3disc::sendAllInfoToJustConnectedPeer(const std::string &id)
|
||||
|
||||
void p3disc::sendJustConnectedPeerInfoToAllPeer(const std::string &connectedPeerId)
|
||||
{
|
||||
/* get a peer lists */
|
||||
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::sendJustConnectedPeerInfoToAllPeer() connectedPeerId : " << connectedPeerId << std::endl;
|
||||
#endif
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
|
||||
std::string gpg_connectedPeerId = rsPeers->getGPGId(connectedPeerId);
|
||||
std::list<std::string> onlineIds;
|
||||
|
||||
/* get a peer lists */
|
||||
rsPeers->getOnlineList(onlineIds);
|
||||
|
||||
{
|
||||
@ -341,40 +371,45 @@ void p3disc::sendJustConnectedPeerInfoToAllPeer(const std::string &connectedPeer
|
||||
|
||||
/* append gpg id's of all friend's to the sending list */
|
||||
|
||||
std::list<std::string>::iterator onlineIdsIt;
|
||||
for (onlineIdsIt = onlineIds.begin(); onlineIdsIt != onlineIds.end(); onlineIdsIt++) {
|
||||
std::list<std::string> &idList = sendIdList[*onlineIdsIt];
|
||||
if (std::find(idList.begin(), idList.end(), gpg_connectedPeerId) == idList.end()) {
|
||||
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
|
||||
idList.push_back(gpg_connectedPeerId);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::sendJustConnectedPeerInfoToAllPeer() already in queue for: ";
|
||||
std::cerr << *it << std::endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool isDummyFriend(const std::string &id)
|
||||
{
|
||||
bool ret = (id.substr(0,5) == "dummy");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* (dest (to), source (cert)) */
|
||||
RsDiscReply *p3disc::createDiscReply(const std::string &to, const std::string &about)
|
||||
{
|
||||
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::createDiscReply() called. Sending details of: " << about << " to: " << to << std::endl;
|
||||
#endif
|
||||
|
||||
RsPeerDetails pd;
|
||||
rsPeers->getPeerDetails(to, pd);
|
||||
if (pd.gpg_id != rsPeers->getGPGOwnId() && (!pd.accept_connection || !pd.ownsign) )
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::createDiscReply() we're not sending the info because the destination gpg key is not signed or not accepted." << std::cerr << std::endl;
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
// if off discard item.
|
||||
peerState detail;
|
||||
if (!mPeerMgr->getOwnNetStatus(detail) || (detail.visState & RS_VIS_STATE_NODISC)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
std::string aboutGpgId = rsPeers->getGPGId(about);
|
||||
if (aboutGpgId.empty()) {
|
||||
#ifdef P3DISC_DEBUG
|
||||
@ -383,6 +418,7 @@ RsDiscReply *p3disc::createDiscReply(const std::string &to, const std::string &a
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
// Construct a message
|
||||
RsDiscReply *di = new RsDiscReply();
|
||||
|
||||
@ -393,36 +429,56 @@ RsDiscReply *p3disc::createDiscReply(const std::string &to, const std::string &a
|
||||
|
||||
// set the ip addresse list.
|
||||
std::list<std::string> sslChilds;
|
||||
rsPeers->getSSLChildListOfGPGId(aboutGpgId, sslChilds);
|
||||
rsPeers->getAssociatedSSLIds(aboutGpgId, sslChilds);
|
||||
bool shouldWeSendGPGKey = false;//the GPG key is send only if we've got a valid friend with DISC enabled
|
||||
|
||||
std::list<std::string>::iterator sslChildIt;
|
||||
for (sslChildIt = sslChilds.begin(); sslChildIt != sslChilds.end(); sslChildIt++)
|
||||
if(!rsPeers->isDummyFriend(*sslChildIt))
|
||||
{
|
||||
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
||||
if (!mDiscEnabled)
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::createDiscReply() Found Child SSL Id:" << *sslChildIt;
|
||||
std::cerr << "p3disc::createDiscReply() Disc Disabled, removing all friend SSL Ids";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
if(sslChilds.size() == 1 || to != *sslChildIt) // We don't send info to a peer about itself, when there are more than one ssl children,
|
||||
{ // but we allow sending info about peers with the same GPG id. When there is only one ssl child,
|
||||
// we must send it to transfer the signers of the gpg key. The receiver is skipping the own id.
|
||||
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))
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::createDiscReply() Skipping Dummy Child SSL Id:" << *it;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
||||
peerState detail;
|
||||
if (!mPeerMgr->getFriendNetStatus(*sslChildIt, detail)
|
||||
if (!mPeerMgr->getFriendNetStatus(*it, detail)
|
||||
|| detail.visState & RS_VIS_STATE_NODISC)
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::createDiscReply() Skipping cos No Details or NODISC flag";
|
||||
std::cerr << "p3disc::createDiscReply() Skipping cos No Details or NODISC flag id: " << *it;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
||||
#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();
|
||||
|
||||
@ -441,19 +497,15 @@ RsDiscReply *p3disc::createDiscReply(const std::string &to, const std::string &a
|
||||
|
||||
di->rsPeerList.push_back(rsPeerNetItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::createDiscReply() Skipping cos \"to == sslChildId\"";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//send own details
|
||||
if (about == rsPeers->getGPGOwnId())
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::createDiscReply() Adding Own Id Details";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
peerState detail;
|
||||
if (mPeerMgr->getOwnNetStatus(detail))
|
||||
{
|
||||
@ -494,6 +546,16 @@ void p3disc::sendOwnVersion(std::string to)
|
||||
std::cerr << "p3disc::sendOwnVersion() Sending rs version to: " << to << std::endl;
|
||||
#endif
|
||||
|
||||
/* only ask info if discovery is on */
|
||||
if (!mDiscEnabled)
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::sendOwnVersion() Disc Disabled => NULL OP" << std::endl;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
RsDiscVersion *di = new RsDiscVersion();
|
||||
di->PeerId(to);
|
||||
di->version = RsUtil::retroshareVersion();
|
||||
@ -537,9 +599,11 @@ void p3disc::askInfoToAllPeers(std::string about)
|
||||
std::cerr <<"p3disc::askInfoToAllPeers() about " << about << std::endl;
|
||||
#endif
|
||||
|
||||
// We Still Ask even if Disc isn't Enabled... if they want to give us the info ;)
|
||||
|
||||
|
||||
peerState connectState;
|
||||
if (!mPeerMgr->getFriendNetStatus(about, connectState)) // || (connectState.visState & RS_VIS_STATE_NODISC)) {
|
||||
if (!mPeerMgr->getFriendNetStatus(about, connectState) || (connectState.visState & RS_VIS_STATE_NODISC))
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::askInfoToAllPeers() friend disc is off, don't send the request." << std::endl;
|
||||
@ -548,43 +612,27 @@ void p3disc::askInfoToAllPeers(std::string about)
|
||||
}
|
||||
|
||||
std::string aboutGpgId = rsPeers->getGPGId(about);
|
||||
if (aboutGpgId == "") {
|
||||
if (aboutGpgId == "")
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::askInfoToAllPeers() no gpg id found" << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
// if off discard item.
|
||||
if (!mPeerMgr->getOwnNetStatus(connectState) || (connectState.visState & RS_VIS_STATE_NODISC)) {
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::askInfoToAllPeers() no gpg id found" << std::endl;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
std::list<std::string> onlineIds;
|
||||
std::list<std::string>::iterator onlineIdsIt;
|
||||
std::list<std::string>::iterator it;
|
||||
|
||||
rsPeers->getOnlineList(onlineIds);
|
||||
|
||||
/* ask info to trusted friends */
|
||||
for(onlineIdsIt = onlineIds.begin(); onlineIdsIt != onlineIds.end(); onlineIdsIt++)
|
||||
for(it = onlineIds.begin(); it != onlineIds.end(); it++)
|
||||
{
|
||||
RsPeerDetails details;
|
||||
rsPeers->getPeerDetails(*onlineIdsIt, details);
|
||||
if (!details.accept_connection || !details.ownsign)
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::askInfoToAllPeers() don't ask info message to untrusted peer." << std::endl;
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
RsDiscAskInfo *di = new RsDiscAskInfo();
|
||||
di->PeerId(*onlineIdsIt);
|
||||
di->gpg_id = about;
|
||||
di->PeerId(*it);
|
||||
di->gpg_id = aboutGpgId;
|
||||
sendItem(di);
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::askInfoToAllPeers() question sent to : " << *onlineIdsIt << std::endl;
|
||||
std::cerr << "p3disc::askInfoToAllPeers() question sent to : " << *it << std::endl;
|
||||
#endif
|
||||
}
|
||||
#ifdef P3DISC_DEBUG
|
||||
@ -594,12 +642,6 @@ void p3disc::askInfoToAllPeers(std::string about)
|
||||
|
||||
void p3disc::recvPeerDetails(RsDiscReply *item, const std::string &certGpgId)
|
||||
{
|
||||
// discovery is only disabled for sending, not for receiving.
|
||||
// // if off discard item.
|
||||
// peerConnectState detail;
|
||||
// if (!mConnMgr->getOwnNetStatus(detail) || (detail.visState & RS_VIS_STATE_NODISC)) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::recvPeerFriendMsg() From: " << item->PeerId() << " About " << item->aboutId << std::endl;
|
||||
@ -620,11 +662,17 @@ void p3disc::recvPeerDetails(RsDiscReply *item, const std::string &certGpgId)
|
||||
|
||||
bool should_notify_discovery = false ;
|
||||
|
||||
for (std::list<RsPeerNetItem>::iterator pitem = item->rsPeerList.begin(); pitem != item->rsPeerList.end(); pitem++)
|
||||
if(!rsPeers->isDummyFriend(pitem->pid))
|
||||
std::list<RsPeerNetItem>::iterator pit;
|
||||
for (pit = item->rsPeerList.begin(); pit != item->rsPeerList.end(); pit++)
|
||||
{
|
||||
bool new_info ;
|
||||
addDiscoveryData(item->PeerId(), pitem->pid,rsPeers->getGPGId(item->PeerId()),item->aboutId, pitem->currentlocaladdr, pitem->currentremoteaddr, 0, time(NULL),new_info);
|
||||
if(isDummyFriend(pit->pid))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
bool new_info = false;
|
||||
addDiscoveryData(item->PeerId(), pit->pid,rsPeers->getGPGId(item->PeerId()),
|
||||
item->aboutId, pit->currentlocaladdr, pit->currentremoteaddr, 0, time(NULL),new_info);
|
||||
|
||||
if(new_info)
|
||||
should_notify_discovery = true ;
|
||||
@ -632,101 +680,83 @@ void p3disc::recvPeerDetails(RsDiscReply *item, const std::string &certGpgId)
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::recvPeerFriendMsg() Peer Config Item:" << std::endl;
|
||||
|
||||
pitem->print(std::cerr, 10);
|
||||
pit->print(std::cerr, 10);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
if (pitem->pid != rsPeers->getOwnId())
|
||||
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.
|
||||
//
|
||||
if(AuthGPG::getAuthGPG()->isGPGAccepted(pitem->gpg_id) || pitem->gpg_id == AuthGPG::getAuthGPG()->getGPGOwnId())
|
||||
|
||||
// Check if already friend.
|
||||
if(AuthGPG::getAuthGPG()->isGPGAccepted(pit->gpg_id) || pit->gpg_id == AuthGPG::getAuthGPG()->getGPGOwnId())
|
||||
{
|
||||
if (!mPeerMgr->isFriend(pit->pid))
|
||||
{
|
||||
// Add with no disc by default. If friend already exists, it will do nothing
|
||||
//
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "--> Adding to friends list " << pitem->pid << " - " << pitem->gpg_id << std::endl;
|
||||
#endif
|
||||
mPeerMgr->addFriend(pitem->pid, pitem->gpg_id, pitem->netMode, 0, 0);
|
||||
RsPeerDetails storedDetails;
|
||||
// NO DISC is important - otherwise, we'll just enter a nasty loop,
|
||||
// where every addition triggers requests, then they are cleaned up, and readded...
|
||||
|
||||
// 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))
|
||||
{
|
||||
// This way we get their addresses, but don't advertise them until we get a
|
||||
// connection.
|
||||
#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;
|
||||
std::cerr << "--> Adding to friends list " << pit->pid << " - " << pit->gpg_id << std::endl;
|
||||
#endif
|
||||
mPeerMgr->setNetworkMode(pitem->pid, pitem->netMode);
|
||||
mPeerMgr->addFriend(pit->pid, pit->gpg_id, pit->netMode, RS_VIS_STATE_NODISC, 0);
|
||||
}
|
||||
}
|
||||
mPeerMgr->setLocation(pitem->pid, pitem->location);
|
||||
|
||||
// The info from the peer itself is ultimately trustable, so we can override some info,
|
||||
// such as:
|
||||
// - local and global addresses
|
||||
// - address list
|
||||
//
|
||||
// If we enter here, we're necessarily connected to this peer.
|
||||
//
|
||||
if (item->PeerId() == pitem->pid)
|
||||
/* skip if not one of our peers */
|
||||
if (!mPeerMgr->isFriend(pit->pid))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item->PeerId() == pit->pid)
|
||||
{
|
||||
std::cerr << "Info sent by the peer itself -> updating self info:" << std::endl;
|
||||
std::cerr << " -> current local addr = " << pitem->currentlocaladdr << std::endl;
|
||||
std::cerr << " -> current remote addr = " << pitem->currentremoteaddr << std::endl;
|
||||
//std::cerr << " -> clearing NODISC flag " << std::endl;
|
||||
std::cerr << " -> visState = " << std::hex << pitem->visState << std::dec;
|
||||
std::cerr << std::endl;
|
||||
#ifdef P3DISC_DEBUG
|
||||
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;
|
||||
#endif
|
||||
|
||||
// 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);
|
||||
|
||||
mPeerMgr->setLocalAddress(pitem->pid, pitem->currentlocaladdr);
|
||||
mPeerMgr->setExtAddress(pitem->pid, pitem->currentremoteaddr);
|
||||
//pitem->visState &= ~RS_VIS_STATE_NODISC ;
|
||||
mPeerMgr->setVisState(pitem->pid, pitem->visState);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "p3disc:: ERROR HOW DID WE GET HERE?" << std::endl;
|
||||
if (pit->dyndns != "")
|
||||
mPeerMgr->setDynDNS(pit->pid, pit->dyndns);
|
||||
}
|
||||
|
||||
// always update historical address list... this should be enough to let us connect.
|
||||
|
||||
pqiIpAddrSet addrsFromPeer;
|
||||
addrsFromPeer.mLocal.extractFromTlv(pitem->localAddrList);
|
||||
addrsFromPeer.mExt.extractFromTlv(pitem->extAddrList);
|
||||
addrsFromPeer.mLocal.extractFromTlv(pit->localAddrList);
|
||||
addrsFromPeer.mExt.extractFromTlv(pit->extAddrList);
|
||||
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "Setting address list to peer " << pitem->pid << ", to be:" << std::endl ;
|
||||
std::cerr << "Setting address list to peer " << pit->pid << ", to be:" << std::endl ;
|
||||
|
||||
addrsFromPeer.printAddrs(std::cerr);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
// allways update address list and dns, except if it's ours
|
||||
if (pitem->dyndns != "")
|
||||
mPeerMgr->setDynDNS(pitem->pid, pitem->dyndns);
|
||||
mPeerMgr->updateAddressList(pit->pid, addrsFromPeer);
|
||||
|
||||
mPeerMgr->updateAddressList(pitem->pid, addrsFromPeer);
|
||||
}
|
||||
#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 ;
|
||||
std::cerr << "Skipping info about own id " << pit->pid << std::endl ;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -765,21 +795,60 @@ void p3disc::recvHeartbeatMsg(RsDiscHeartbeat *item)
|
||||
return;
|
||||
}
|
||||
|
||||
void p3disc::recvAskInfo(RsDiscAskInfo *item) {
|
||||
void p3disc::recvAskInfo(RsDiscAskInfo *item)
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::recvAskInfo() From: " << item->PeerId();
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::list<std::string> &idList = sendIdList[item->PeerId()];
|
||||
/* 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;
|
||||
}
|
||||
|
||||
std::list<std::string> &idList = mSendIdList[item->PeerId()];
|
||||
|
||||
if (std::find(idList.begin(), idList.end(), item->gpg_id) == idList.end()) {
|
||||
idList.push_back(item->gpg_id);
|
||||
}
|
||||
}
|
||||
|
||||
void p3disc::removeFriend(std::string ssl_id) {
|
||||
void p3disc::recvDiscReply(RsDiscReply *dri)
|
||||
{
|
||||
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
/* 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
|
||||
mPendingDiscReplyInList.push_back(dri); // no delete
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void p3disc::removeFriend(std::string ssl_id)
|
||||
{
|
||||
|
||||
// DON'T KNOW WHY SSL IDS were saved -> the results are never used
|
||||
#if 0
|
||||
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::removeFriend() called for : " << ssl_id << std::endl;
|
||||
#endif
|
||||
@ -795,6 +864,9 @@ void p3disc::removeFriend(std::string ssl_id) {
|
||||
deletedSSLFriendsIds[ssl_id] = time(NULL);//just keep track of the deleted time
|
||||
IndicateConfigChanged();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/*************************************************************************************/
|
||||
@ -806,8 +878,8 @@ AuthGPGOperation *p3disc::getGPGOperation()
|
||||
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
/* process disc reply in list */
|
||||
if (pendingDiscReplyInList.empty() == false) {
|
||||
RsDiscReply *item = pendingDiscReplyInList.front();
|
||||
if (mPendingDiscReplyInList.empty() == false) {
|
||||
RsDiscReply *item = mPendingDiscReplyInList.front();
|
||||
|
||||
return new AuthGPGOperationLoadOrSave(true, item->certGPG, item);
|
||||
}
|
||||
@ -821,20 +893,21 @@ AuthGPGOperation *p3disc::getGPGOperation()
|
||||
{
|
||||
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
while (!sendIdList.empty()) {
|
||||
std::map<std::string, std::list<std::string> >::iterator sendIdIt = sendIdList.begin();
|
||||
while (!mSendIdList.empty())
|
||||
{
|
||||
std::map<std::string, std::list<std::string> >::iterator it = mSendIdList.begin();
|
||||
|
||||
if (!sendIdIt->second.empty() && mLinkMgr->isOnline(sendIdIt->first)) {
|
||||
std::string gpgId = sendIdIt->second.front();
|
||||
sendIdIt->second.pop_front();
|
||||
if (!it->second.empty() && mLinkMgr->isOnline(it->first)) {
|
||||
std::string gpgId = it->second.front();
|
||||
it->second.pop_front();
|
||||
|
||||
destId = sendIdIt->first;
|
||||
destId = it->first;
|
||||
srcId = gpgId;
|
||||
|
||||
break;
|
||||
} else {
|
||||
/* peer is not online anymore ... try next */
|
||||
sendIdList.erase(sendIdIt);
|
||||
mSendIdList.erase(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -860,10 +933,11 @@ void p3disc::setGPGOperation(AuthGPGOperation *operation)
|
||||
{
|
||||
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::list<RsDiscReply*>::iterator it = std::find(pendingDiscReplyInList.begin(), pendingDiscReplyInList.end(), loadOrSave->m_userdata);
|
||||
if (it != pendingDiscReplyInList.end()) {
|
||||
std::list<RsDiscReply*>::iterator it;
|
||||
it = std::find(mPendingDiscReplyInList.begin(), mPendingDiscReplyInList.end(), loadOrSave->m_userdata);
|
||||
if (it != mPendingDiscReplyInList.end()) {
|
||||
item = *it;
|
||||
pendingDiscReplyInList.erase(it);
|
||||
mPendingDiscReplyInList.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1002,6 +1076,8 @@ bool p3disc::potentialproxies(const std::string& id, std::list<std::string> &pro
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool p3disc::potentialGPGproxies(const std::string& gpg_id, std::list<std::string> &proxyGPGIds)
|
||||
{
|
||||
/* find id -> and extract the neighbour_of ids */
|
||||
@ -1040,13 +1116,13 @@ void p3disc::getWaitingDiscCount(unsigned int *sendCount, unsigned int *recvCoun
|
||||
*sendCount = 0;
|
||||
|
||||
std::map<std::string, std::list<std::string> >::iterator it;
|
||||
for (it = sendIdList.begin(); it != sendIdList.end(); it++) {
|
||||
for (it = mSendIdList.begin(); it != mSendIdList.end(); it++) {
|
||||
*sendCount += it->second.size();
|
||||
}
|
||||
}
|
||||
|
||||
if (recvCount) {
|
||||
*recvCount = pendingDiscReplyInList.size();
|
||||
*recvCount = mPendingDiscReplyInList.size();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1160,11 +1236,13 @@ bool p3disc::saveList(bool& cleanup, std::list<RsItem*>& lst)
|
||||
#endif
|
||||
cleanup = true ;
|
||||
|
||||
|
||||
// DON'T KNOW WHY SSL IDS were saved -> the results are never used
|
||||
#if 0
|
||||
// Now save config for network digging strategies
|
||||
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ;
|
||||
std::map<std::string, time_t>::iterator mapIt;
|
||||
for (mapIt = deletedSSLFriendsIds.begin(); mapIt != deletedSSLFriendsIds.end(); mapIt++) {
|
||||
for (mapIt = deletedSSLFriendsIds.begin(); mapIt != deletedSSLFriendsIds.end(); mapIt++)
|
||||
{
|
||||
RsTlvKeyValue kv;
|
||||
kv.key = mapIt->first;
|
||||
std::ostringstream time_string;
|
||||
@ -1176,6 +1254,7 @@ bool p3disc::saveList(bool& cleanup, std::list<RsItem*>& lst)
|
||||
#endif
|
||||
}
|
||||
lst.push_back(vitem);
|
||||
#endif
|
||||
|
||||
return true ;
|
||||
}
|
||||
@ -1186,14 +1265,19 @@ bool p3disc::loadList(std::list<RsItem*>& load)
|
||||
std::cerr << "p3disc::loadList() Item Count: " << load.size() << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
RsStackMutex stack(mDiscMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
/* load the list of accepted gpg keys */
|
||||
std::list<RsItem *>::iterator it;
|
||||
for(it = load.begin(); it != load.end(); it++) {
|
||||
for(it = load.begin(); it != load.end(); it++)
|
||||
{
|
||||
RsConfigKeyValueSet *vitem = dynamic_cast<RsConfigKeyValueSet *>(*it);
|
||||
|
||||
if(vitem) {
|
||||
// DON'T KNOW WHY SSL IDS were saved -> the results are never used
|
||||
#if 0
|
||||
if(vitem)
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::loadList() General Variable Config Item:" << std::endl;
|
||||
vitem->print(std::cerr, 10);
|
||||
@ -1201,13 +1285,16 @@ bool p3disc::loadList(std::list<RsItem*>& load)
|
||||
#endif
|
||||
|
||||
std::list<RsTlvKeyValue>::iterator kit;
|
||||
for(kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); kit++) {
|
||||
for(kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); kit++)
|
||||
{
|
||||
std::istringstream instream(kit->value);
|
||||
time_t deleted_time_t;
|
||||
instream >> deleted_time_t;
|
||||
deletedSSLFriendsIds[kit->key] = deleted_time_t;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
delete (*it);
|
||||
}
|
||||
return true;
|
||||
|
@ -129,6 +129,7 @@ void recvPeerDetails(RsDiscReply *item, const std::string &certGpgId);
|
||||
//void recvPeerIssuerMsg(RsDiscIssuer *item);
|
||||
void recvPeerVersionMsg(RsDiscVersion *item);
|
||||
void recvHeartbeatMsg(RsDiscHeartbeat *item);
|
||||
void recvDiscReply(RsDiscReply *dri);
|
||||
|
||||
void removeFriend(std::string ssl_id); //keep tracks of removed friend so we're not gonna add them again immediately
|
||||
|
||||
@ -146,22 +147,27 @@ int idServers();
|
||||
p3LinkMgr *mLinkMgr;
|
||||
|
||||
pqipersongrp *mPqiPersonGrp;
|
||||
time_t lastSentHeartbeatTime;
|
||||
|
||||
/* data */
|
||||
RsMutex mDiscMtx;
|
||||
|
||||
std::map<std::string, time_t> deletedSSLFriendsIds;
|
||||
time_t mLastSentHeartbeatTime;
|
||||
bool mDiscEnabled;
|
||||
|
||||
std::map<std::string, autoneighbour> neighbours;
|
||||
std::map<std::string, std::string> versions;
|
||||
//std::map<std::string, time_t> deletedSSLFriendsIds;
|
||||
|
||||
std::map<std::string, std::list<std::string> > sendIdList;
|
||||
std::list<RsDiscReply*> pendingDiscReplyInList;
|
||||
|
||||
std::map<std::string, std::list<std::string> > mSendIdList;
|
||||
std::list<RsDiscReply*> mPendingDiscReplyInList;
|
||||
|
||||
// Neighbors at the gpg level.
|
||||
//
|
||||
std::map<std::string,std::set<std::string> > gpg_neighbors ;
|
||||
|
||||
// Original mapping.
|
||||
std::map<std::string, autoneighbour> neighbours;
|
||||
|
||||
// Rs Version.
|
||||
std::map<std::string, std::string> versions;
|
||||
};
|
||||
|
||||
|
||||
|
@ -49,6 +49,7 @@
|
||||
#include "pqi/authssl.h"
|
||||
#include "pqi/authgpg.h"
|
||||
|
||||
#include "retroshare/rspeers.h" // Needed for RsPeerDetails & Online List. (Should remove dependance)
|
||||
|
||||
#define FAILED_CACHE_CONT "failedcachegrp" // cache id which have failed are stored under a node of this name/grpid
|
||||
#define HIST_CACHE_FNAME "grp_history.xml"
|
||||
|
@ -24,9 +24,9 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "retroshare/rsiface.h"
|
||||
#include "retroshare/rsinit.h" /* for PGPSSL flag */
|
||||
#include "retroshare/rspeers.h"
|
||||
//#include "retroshare/rsiface.h"
|
||||
//#include "retroshare/rsinit.h" /* for PGPSSL flag */
|
||||
//#include "retroshare/rspeers.h"
|
||||
#include "services/p3tunnel.h"
|
||||
#include "pqi/pqissltunnel.h"
|
||||
#include <sstream>
|
||||
|
@ -33,8 +33,6 @@
|
||||
#endif
|
||||
|
||||
#include "retroshare/rsiface.h"
|
||||
#include "retroshare/rspeers.h"
|
||||
#include "retroshare/rsfiles.h"
|
||||
|
||||
#include "pqi/authssl.h"
|
||||
#include "pqi/p3linkmgr.h"
|
||||
@ -2153,15 +2151,14 @@ void p3turtle::getInfo( std::vector<std::vector<std::string> >& hashes_info,
|
||||
|
||||
tunnel.push_back(printNumber(it->first,true)) ;
|
||||
|
||||
RsPeerDetails sslDetails;
|
||||
|
||||
if(rsPeers->getPeerDetails(it->second.local_src,sslDetails))
|
||||
tunnel.push_back(sslDetails.name + " - " + sslDetails.location) ;
|
||||
std::string name;
|
||||
if(mLinkMgr->getPeerName(it->second.local_src,name))
|
||||
tunnel.push_back(name) ;
|
||||
else
|
||||
tunnel.push_back(it->second.local_src) ;
|
||||
|
||||
if(rsPeers->getPeerDetails(it->second.local_dst,sslDetails))
|
||||
tunnel.push_back(sslDetails.name + " - " + sslDetails.location) ;
|
||||
if(mLinkMgr->getPeerName(it->second.local_dst,name))
|
||||
tunnel.push_back(name) ;
|
||||
else
|
||||
tunnel.push_back(it->second.local_dst);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user