2008-01-25 02:58:29 -05:00
|
|
|
/*
|
|
|
|
* libretroshare/src/rsserver: p3peers.cc
|
|
|
|
*
|
|
|
|
* RetroShare C++ Interface.
|
|
|
|
*
|
|
|
|
* 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".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "rsserver/p3peers.h"
|
2009-02-08 09:30:28 -05:00
|
|
|
#include "rsserver/p3face.h"
|
2011-07-09 14:39:34 -04:00
|
|
|
|
|
|
|
#include "pqi/p3linkmgr.h"
|
|
|
|
#include "pqi/p3peermgr.h"
|
|
|
|
#include "pqi/p3netmgr.h"
|
|
|
|
|
2010-01-13 15:56:55 -05:00
|
|
|
#include "pqi/authssl.h"
|
2010-01-13 15:58:58 -05:00
|
|
|
#include "pqi/authgpg.h"
|
2010-08-06 05:40:23 -04:00
|
|
|
#include "retroshare/rsinit.h"
|
2010-01-19 17:06:42 -05:00
|
|
|
#include "pqi/cleanupxpgp.h"
|
2010-01-13 16:29:21 -05:00
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
|
|
|
|
#include <iostream>
|
2008-06-19 17:34:13 -04:00
|
|
|
#include <fstream>
|
2008-01-25 02:58:29 -05:00
|
|
|
#include <sstream>
|
|
|
|
|
2010-02-14 09:18:53 -05:00
|
|
|
#include <gpgme.h>
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2010-01-13 16:30:44 -05:00
|
|
|
const std::string CERT_SSL_ID = "--SSLID--";
|
|
|
|
const std::string CERT_LOCATION = "--LOCATION--";
|
|
|
|
const std::string CERT_LOCAL_IP = "--LOCAL--";
|
|
|
|
const std::string CERT_EXT_IP = "--EXT--";
|
2010-04-22 14:49:08 -04:00
|
|
|
const std::string CERT_DYNDNS = "--DYNDNS--";
|
2010-01-13 16:29:21 -05:00
|
|
|
|
2010-12-14 16:56:37 -05:00
|
|
|
static const int MAX_TIME_KEEP_LOCATION_WITHOUT_CONTACT = 30*24*3600 ; // 30 days.
|
2010-01-13 16:29:21 -05:00
|
|
|
|
|
|
|
|
|
|
|
#include "pqi/authssl.h"
|
2008-11-09 17:17:20 -05:00
|
|
|
|
2008-06-19 17:34:13 -04:00
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
RsPeers *rsPeers = NULL;
|
|
|
|
|
2008-06-13 11:42:08 -04:00
|
|
|
/*******
|
|
|
|
* #define P3PEERS_DEBUG 1
|
|
|
|
*******/
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
int ensureExtension(std::string &name, std::string def_ext);
|
|
|
|
|
|
|
|
std::string RsPeerTrustString(uint32_t trustLvl)
|
|
|
|
{
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
std::string str;
|
2009-05-23 11:07:35 -04:00
|
|
|
|
|
|
|
switch(trustLvl)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case GPGME_VALIDITY_UNKNOWN:
|
|
|
|
str = "GPGME_VALIDITY_UNKNOWN";
|
|
|
|
break;
|
|
|
|
case GPGME_VALIDITY_UNDEFINED:
|
|
|
|
str = "GPGME_VALIDITY_UNDEFINED";
|
|
|
|
break;
|
|
|
|
case GPGME_VALIDITY_NEVER:
|
|
|
|
str = "GPGME_VALIDITY_NEVER";
|
|
|
|
break;
|
|
|
|
case GPGME_VALIDITY_MARGINAL:
|
|
|
|
str = "GPGME_VALIDITY_MARGINAL";
|
|
|
|
break;
|
|
|
|
case GPGME_VALIDITY_FULL:
|
|
|
|
str = "GPGME_VALIDITY_FULL";
|
|
|
|
break;
|
|
|
|
case GPGME_VALIDITY_ULTIMATE:
|
|
|
|
str = "GPGME_VALIDITY_ULTIMATE";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return str;
|
2008-01-25 02:58:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string RsPeerNetModeString(uint32_t netModel)
|
|
|
|
{
|
|
|
|
std::string str;
|
|
|
|
if (netModel == RS_NETMODE_EXT)
|
|
|
|
{
|
|
|
|
str = "External Port";
|
|
|
|
}
|
|
|
|
else if (netModel == RS_NETMODE_UPNP)
|
|
|
|
{
|
|
|
|
str = "Ext (UPnP)";
|
|
|
|
}
|
|
|
|
else if (netModel == RS_NETMODE_UDP)
|
|
|
|
{
|
|
|
|
str = "UDP Mode";
|
|
|
|
}
|
2008-02-28 10:58:54 -05:00
|
|
|
else if (netModel == RS_NETMODE_UNREACHABLE)
|
|
|
|
{
|
|
|
|
str = "UDP Mode (Unreachable)";
|
|
|
|
}
|
2008-01-25 02:58:29 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
str = "Unknown NetMode";
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string RsPeerLastConnectString(uint32_t lastConnect)
|
|
|
|
{
|
|
|
|
std::ostringstream out;
|
|
|
|
out << lastConnect << " secs ago";
|
|
|
|
return out.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-09 14:39:34 -04:00
|
|
|
p3Peers::p3Peers(p3LinkMgr *lm, p3PeerMgr *pm, p3NetMgr *nm)
|
|
|
|
:mLinkMgr(lm), mPeerMgr(pm), mNetMgr(nm)
|
2008-01-25 02:58:29 -05:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-01 16:47:58 -04:00
|
|
|
bool p3Peers::hasExportMinimal()
|
|
|
|
{
|
|
|
|
#ifdef GPGME_EXPORT_MODE_MINIMAL
|
|
|
|
return true ;
|
|
|
|
#else
|
|
|
|
return false ;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
/* Updates ... */
|
|
|
|
bool p3Peers::FriendsChanged()
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
2010-02-07 18:01:18 -05:00
|
|
|
std::cerr << "p3Peers::FriendsChanged()" << std::endl;
|
2008-01-25 02:58:29 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* TODO */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool p3Peers::OthersChanged()
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
2010-02-07 18:01:18 -05:00
|
|
|
std::cerr << "p3Peers::OthersChanged()" << std::endl;
|
2008-01-25 02:58:29 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* TODO */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Peer Details (Net & Auth) */
|
|
|
|
std::string p3Peers::getOwnId()
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
2010-02-07 18:01:18 -05:00
|
|
|
std::cerr << "p3Peers::getOwnId()" << std::endl;
|
2008-01-25 02:58:29 -05:00
|
|
|
#endif
|
|
|
|
|
2010-01-13 15:58:58 -05:00
|
|
|
return AuthSSL::getAuthSSL()->OwnId();
|
2008-01-25 02:58:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool p3Peers::getOnlineList(std::list<std::string> &ids)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
2010-02-07 18:01:18 -05:00
|
|
|
std::cerr << "p3Peers::getOnlineList()" << std::endl;
|
2008-01-25 02:58:29 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* get from mConnectMgr */
|
2011-07-09 14:39:34 -04:00
|
|
|
mLinkMgr->getOnlineList(ids);
|
2008-01-25 02:58:29 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool p3Peers::getFriendList(std::list<std::string> &ids)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
2010-02-07 18:01:18 -05:00
|
|
|
std::cerr << "p3Peers::getFriendList()" << std::endl;
|
2008-01-25 02:58:29 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* get from mConnectMgr */
|
2011-07-09 14:39:34 -04:00
|
|
|
mLinkMgr->getFriendList(ids);
|
2008-01-25 02:58:29 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-01-13 16:22:52 -05:00
|
|
|
//bool p3Peers::getOthersList(std::list<std::string> &ids)
|
|
|
|
//{
|
|
|
|
//#ifdef P3PEERS_DEBUG
|
|
|
|
// std::cerr << "p3Peers::getOthersList()";
|
|
|
|
// std::cerr << std::endl;
|
|
|
|
//#endif
|
|
|
|
//
|
|
|
|
// /* get from mAuthMgr */
|
|
|
|
// AuthSSL::getAuthSSL()->getAllList(ids);
|
|
|
|
// return true;
|
|
|
|
//}
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2011-08-12 09:42:30 -04:00
|
|
|
bool p3Peers::getPeerCount (unsigned int *pnFriendCount, unsigned int *pnOnlineCount, bool /*ssl*/)
|
2010-05-13 15:20:40 -04:00
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::getPeerCount()" << std::endl;
|
|
|
|
#endif
|
2011-07-09 14:39:34 -04:00
|
|
|
// This is no longer accurate!
|
|
|
|
*pnFriendCount = mLinkMgr->getFriendCount();
|
|
|
|
*pnOnlineCount = mLinkMgr->getOnlineCount();
|
|
|
|
|
|
|
|
/* get from mConnectMgr */
|
|
|
|
//return mConnMgr->getPeerCount(pnFriendCount, pnOnlineCount, ssl);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
2010-05-13 15:20:40 -04:00
|
|
|
}
|
|
|
|
|
2010-11-06 12:40:18 -04:00
|
|
|
bool p3Peers::isOnline(const std::string &id)
|
2008-06-16 16:37:48 -04:00
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
2010-02-07 18:01:18 -05:00
|
|
|
std::cerr << "p3Peers::isOnline() " << id << std::endl;
|
2008-06-16 16:37:48 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* get from mConnectMgr */
|
|
|
|
peerConnectState state;
|
2011-07-09 14:39:34 -04:00
|
|
|
if (mLinkMgr->getFriendNetStatus(id, state) &&
|
2008-06-16 16:37:48 -04:00
|
|
|
(state.state & RS_PEER_S_CONNECTED))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-11-06 12:40:18 -04:00
|
|
|
bool p3Peers::isFriend(const std::string &ssl_id)
|
2008-01-25 02:58:29 -05:00
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
2010-02-07 18:01:18 -05:00
|
|
|
std::cerr << "p3Peers::isFriend() " << ssl_id << std::endl;
|
2008-01-25 02:58:29 -05:00
|
|
|
#endif
|
|
|
|
|
2010-01-13 16:25:18 -05:00
|
|
|
/* get from mConnectMgr */
|
2011-07-09 14:39:34 -04:00
|
|
|
return mPeerMgr->isFriend(ssl_id);
|
2008-01-25 02:58:29 -05:00
|
|
|
}
|
|
|
|
|
2009-11-07 17:06:12 -05:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
/* 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
|
2011-08-10 07:00:34 -04:00
|
|
|
d.isOnlyGPGdetail = true;
|
2011-08-07 17:11:00 -04:00
|
|
|
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
|
2010-11-06 12:40:18 -04:00
|
|
|
bool p3Peers::getPeerDetails(const std::string &id, RsPeerDetails &d)
|
2008-01-25 02:58:29 -05:00
|
|
|
{
|
2010-01-13 16:16:18 -05:00
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::getPeerDetails() called for id : " << id << std::endl;
|
|
|
|
#endif
|
2010-01-13 16:14:49 -05:00
|
|
|
//first, check if it's a gpg or a ssl id.
|
2010-06-13 08:26:23 -04:00
|
|
|
std::string sOwnId = AuthSSL::getAuthSSL()->OwnId();
|
2011-07-09 14:39:34 -04:00
|
|
|
peerState ps;
|
|
|
|
if (id != sOwnId && !mPeerMgr->getFriendNetStatus(id, ps)) {
|
2010-01-13 16:22:52 -05:00
|
|
|
//assume is not SSL, because every ssl_id has got a friend correspondance in mConnMgr
|
2010-01-13 16:16:18 -05:00
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::getPeerDetails() got a gpg id and is returning GPG details only for id : " << id << std::endl;
|
|
|
|
#endif
|
2010-01-13 16:14:49 -05:00
|
|
|
d.isOnlyGPGdetail = true;
|
2010-01-13 16:22:52 -05:00
|
|
|
return this->getGPGDetails(id, d);
|
2010-01-13 16:14:49 -05:00
|
|
|
}
|
2010-01-13 16:16:18 -05:00
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::getPeerDetails() got a SSL id and is returning SSL and GPG details for id : " << id << std::endl;
|
|
|
|
#endif
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2010-06-13 08:26:23 -04:00
|
|
|
if (id == sOwnId) {
|
2011-07-09 14:39:34 -04:00
|
|
|
mPeerMgr->getOwnNetStatus(ps);
|
|
|
|
ps.gpg_id = AuthGPG::getAuthGPG()->getGPGOwnId();
|
2010-01-13 16:22:52 -05:00
|
|
|
}
|
|
|
|
|
2010-01-13 16:12:56 -05:00
|
|
|
/* get from gpg (first), to fill in the sign and trust details */
|
2010-01-13 16:14:49 -05:00
|
|
|
/* don't retrun now, we've got fill in the ssl and connection info */
|
2011-07-09 14:39:34 -04:00
|
|
|
this->getGPGDetails(ps.gpg_id, d);
|
2010-01-13 16:14:49 -05:00
|
|
|
d.isOnlyGPGdetail = false;
|
2010-01-13 16:12:56 -05:00
|
|
|
|
|
|
|
//get the ssl details
|
2010-01-13 16:22:52 -05:00
|
|
|
d.id = id;
|
2011-07-09 14:39:34 -04:00
|
|
|
d.location = ps.location;
|
2009-08-09 09:06:24 -04:00
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
/* generate */
|
|
|
|
d.authcode = "AUTHCODE";
|
|
|
|
|
|
|
|
/* fill from pcs */
|
|
|
|
|
2011-07-09 14:39:34 -04:00
|
|
|
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;
|
2008-01-25 02:58:29 -05:00
|
|
|
d.connectPeriod = 0;
|
2010-07-04 06:42:17 -04:00
|
|
|
|
|
|
|
|
|
|
|
std::list<pqiIpAddress>::iterator it;
|
2011-07-09 14:39:34 -04:00
|
|
|
for(it = ps.ipAddrs.mLocal.mAddrs.begin();
|
|
|
|
it != ps.ipAddrs.mLocal.mAddrs.end(); it++)
|
2010-07-04 09:19:09 -04:00
|
|
|
{
|
|
|
|
std::ostringstream toto;
|
|
|
|
toto << ntohs(it->mAddr.sin_port) << " " << (time(NULL) - it->mSeenTime) << " sec";
|
2010-07-10 16:34:03 -04:00
|
|
|
d.ipAddressList.push_back("L:" + std::string(rs_inet_ntoa(it->mAddr.sin_addr)) + ":" + toto.str());
|
2010-07-04 09:19:09 -04:00
|
|
|
}
|
2011-07-09 14:39:34 -04:00
|
|
|
for(it = ps.ipAddrs.mExt.mAddrs.begin();
|
|
|
|
it != ps.ipAddrs.mExt.mAddrs.end(); it++)
|
2010-07-04 06:42:17 -04:00
|
|
|
{
|
2009-11-11 17:12:50 -05:00
|
|
|
std::ostringstream toto;
|
2010-07-04 06:42:17 -04:00
|
|
|
toto << ntohs(it->mAddr.sin_port) << " " << (time(NULL) - it->mSeenTime) << " sec";
|
2010-07-10 16:34:03 -04:00
|
|
|
d.ipAddressList.push_back("E:" + std::string(rs_inet_ntoa(it->mAddr.sin_addr)) + ":" + toto.str());
|
2009-11-11 17:12:50 -05:00
|
|
|
}
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2011-07-09 14:39:34 -04:00
|
|
|
switch(ps.netMode & RS_NET_MODE_ACTUAL)
|
2008-02-07 11:18:34 -05:00
|
|
|
{
|
|
|
|
case RS_NET_MODE_EXT:
|
|
|
|
d.netMode = RS_NETMODE_EXT;
|
|
|
|
break;
|
2008-02-26 11:14:13 -05:00
|
|
|
case RS_NET_MODE_UPNP:
|
|
|
|
d.netMode = RS_NETMODE_UPNP;
|
2008-02-07 11:18:34 -05:00
|
|
|
break;
|
2008-02-26 11:14:13 -05:00
|
|
|
case RS_NET_MODE_UDP:
|
2008-02-28 10:58:54 -05:00
|
|
|
d.netMode = RS_NETMODE_UDP;
|
|
|
|
break;
|
|
|
|
case RS_NET_MODE_UNREACHABLE:
|
2008-02-07 11:18:34 -05:00
|
|
|
case RS_NET_MODE_UNKNOWN:
|
|
|
|
default:
|
2008-02-28 10:58:54 -05:00
|
|
|
d.netMode = RS_NETMODE_UNREACHABLE;
|
2008-02-07 11:18:34 -05:00
|
|
|
break;
|
|
|
|
}
|
2011-07-09 14:39:34 -04:00
|
|
|
|
|
|
|
|
|
|
|
if (ps.netMode & RS_NET_MODE_TRY_EXT)
|
2008-02-26 11:14:13 -05:00
|
|
|
{
|
|
|
|
d.tryNetMode = RS_NETMODE_EXT;
|
|
|
|
}
|
2011-07-09 14:39:34 -04:00
|
|
|
else if (ps.netMode & RS_NET_MODE_TRY_UPNP)
|
2008-02-26 11:14:13 -05:00
|
|
|
{
|
|
|
|
d.tryNetMode = RS_NETMODE_UPNP;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d.tryNetMode = RS_NETMODE_UDP;
|
|
|
|
}
|
2011-07-09 14:39:34 -04:00
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
d.visState = 0;
|
2011-07-09 14:39:34 -04:00
|
|
|
if (!(ps.visState & RS_VIS_STATE_NODISC))
|
2008-02-07 11:18:34 -05:00
|
|
|
{
|
|
|
|
d.visState |= RS_VS_DISC_ON;
|
|
|
|
}
|
2011-07-09 14:39:34 -04:00
|
|
|
|
|
|
|
if (!(ps.visState & RS_VIS_STATE_NODHT))
|
2008-02-07 11:18:34 -05:00
|
|
|
{
|
|
|
|
d.visState |= RS_VS_DHT_ON;
|
|
|
|
}
|
2011-07-09 14:39:34 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2008-03-02 09:25:59 -05:00
|
|
|
|
|
|
|
/* Finally determine AutoConnect Status */
|
2011-01-06 13:26:39 -05:00
|
|
|
d.foundDHT = pcs.dht.found;
|
|
|
|
|
|
|
|
d.connectState = 0;
|
|
|
|
d.connectStateString.clear();
|
2010-10-01 20:52:59 -04:00
|
|
|
|
|
|
|
|
2008-03-02 09:25:59 -05:00
|
|
|
if (pcs.inConnAttempt)
|
|
|
|
{
|
2011-01-06 13:26:39 -05:00
|
|
|
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();
|
|
|
|
}
|
2008-03-02 09:25:59 -05:00
|
|
|
}
|
2008-03-26 11:35:09 -04:00
|
|
|
else if (pcs.state & RS_PEER_S_CONNECTED)
|
|
|
|
{
|
|
|
|
if (pcs.connecttype == RS_NET_CONN_TCP_ALL)
|
|
|
|
{
|
2011-01-06 13:26:39 -05:00
|
|
|
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_TCP;
|
2008-03-26 11:35:09 -04:00
|
|
|
}
|
|
|
|
else if (pcs.connecttype == RS_NET_CONN_UDP_ALL)
|
|
|
|
{
|
2011-01-06 13:26:39 -05:00
|
|
|
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_UDP;
|
2008-03-26 11:35:09 -04:00
|
|
|
}
|
2009-12-13 16:59:26 -05:00
|
|
|
else if (pcs.connecttype == RS_NET_CONN_TUNNEL)
|
|
|
|
{
|
2011-01-06 13:26:39 -05:00
|
|
|
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_TUNNEL;
|
2009-12-13 16:59:26 -05:00
|
|
|
}
|
|
|
|
else
|
2008-03-26 11:35:09 -04:00
|
|
|
{
|
2011-01-06 13:26:39 -05:00
|
|
|
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_UNKNOWN;
|
2008-03-26 11:35:09 -04:00
|
|
|
}
|
|
|
|
}
|
2008-03-02 09:25:59 -05:00
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
return true;
|
|
|
|
}
|
2011-08-07 17:11:00 -04:00
|
|
|
#endif
|
2008-01-25 02:58:29 -05:00
|
|
|
|
|
|
|
|
2010-11-06 12:40:18 -04:00
|
|
|
std::string p3Peers::getGPGName(const std::string &gpg_id)
|
2009-11-17 07:45:06 -05:00
|
|
|
{
|
|
|
|
/* get from mAuthMgr as it should have more peers? */
|
2010-01-13 16:22:52 -05:00
|
|
|
return AuthGPG::getAuthGPG()->getGPGName(gpg_id);
|
2009-11-17 07:45:06 -05:00
|
|
|
}
|
|
|
|
|
2010-11-06 12:40:18 -04:00
|
|
|
bool p3Peers::isGPGAccepted(const std::string &gpg_id_is_friend)
|
2010-01-13 16:22:52 -05:00
|
|
|
{
|
|
|
|
/* get from mAuthMgr as it should have more peers? */
|
|
|
|
return AuthGPG::getAuthGPG()->isGPGAccepted(gpg_id_is_friend);
|
|
|
|
}
|
|
|
|
|
2010-11-06 12:40:18 -04:00
|
|
|
std::string p3Peers::getPeerName(const std::string &ssl_or_gpg_id)
|
2008-01-25 02:58:29 -05:00
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
2010-02-07 18:01:18 -05:00
|
|
|
std::cerr << "p3Peers::getPeerName() " << ssl_or_gpg_id << std::endl;
|
2008-01-25 02:58:29 -05:00
|
|
|
#endif
|
2011-08-07 17:11:00 -04:00
|
|
|
std::string name;
|
|
|
|
if (ssl_or_gpg_id == AuthSSL::getAuthSSL()->OwnId())
|
|
|
|
{
|
|
|
|
return AuthGPG::getAuthGPG()->getGPGOwnName();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mPeerMgr->getPeerName(ssl_or_gpg_id, name))
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::getPeerName() got a ssl id. Name is : " << name << std::endl;
|
|
|
|
#endif
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AuthGPG::getAuthGPG()->getGPGName(ssl_or_gpg_id);
|
2008-01-25 02:58:29 -05:00
|
|
|
}
|
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
|
2010-01-13 16:22:52 -05:00
|
|
|
bool p3Peers::getGPGAllList(std::list<std::string> &ids)
|
2009-05-23 11:07:35 -04:00
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
2010-02-07 18:01:18 -05:00
|
|
|
std::cerr << "p3Peers::getGPGAllList()" << std::endl;
|
2009-05-23 11:07:35 -04:00
|
|
|
#endif
|
|
|
|
|
2010-01-13 16:22:52 -05:00
|
|
|
/* get from mAuthMgr */
|
|
|
|
AuthGPG::getAuthGPG()->getGPGAllList(ids);
|
|
|
|
return true;
|
2009-05-23 11:07:35 -04:00
|
|
|
}
|
|
|
|
|
2010-01-13 16:22:52 -05:00
|
|
|
bool p3Peers::getGPGValidList(std::list<std::string> &ids)
|
2010-01-13 16:14:49 -05:00
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
2010-02-07 18:01:18 -05:00
|
|
|
std::cerr << "p3Peers::getPGPOthersList()" << std::endl;
|
2010-01-13 16:14:49 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* get from mAuthMgr */
|
2010-01-13 16:22:52 -05:00
|
|
|
AuthGPG::getAuthGPG()->getGPGValidList(ids);
|
2010-01-13 16:14:49 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-01-13 16:22:52 -05:00
|
|
|
bool p3Peers::getGPGSignedList(std::list<std::string> &ids)
|
2010-01-13 16:14:49 -05:00
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
2010-02-07 18:01:18 -05:00
|
|
|
std::cerr << "p3Peers::getPGPOthersList()" << std::endl;
|
2010-01-13 16:14:49 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* get from mAuthMgr */
|
2010-01-13 16:22:52 -05:00
|
|
|
AuthGPG::getAuthGPG()->getGPGSignedList(ids);
|
2010-01-13 16:14:49 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-01-13 16:22:52 -05:00
|
|
|
bool p3Peers::getGPGAcceptedList(std::list<std::string> &ids)
|
2010-01-13 16:14:49 -05:00
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
2010-02-08 09:06:43 -05:00
|
|
|
std::cerr << "p3Peers::getGPGAcceptedList()" << std::endl;
|
2010-01-13 16:14:49 -05:00
|
|
|
#endif
|
2010-01-13 16:22:52 -05:00
|
|
|
AuthGPG::getAuthGPG()->getGPGAcceptedList(ids);
|
2010-01-13 16:14:49 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
|
|
|
|
bool p3Peers::getAssociatedSSLIds(const std::string &gpg_id, std::list<std::string> &ids)
|
2010-01-13 16:16:18 -05:00
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
2011-08-07 17:11:00 -04:00
|
|
|
std::cerr << "p3Peers::getAssociatedSSLIds() for id : " << gpg_id << std::endl;
|
2010-01-13 16:22:52 -05:00
|
|
|
#endif
|
2010-12-14 16:56:37 -05:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
return mPeerMgr->getAssociatedPeers(gpg_id, ids);
|
2010-01-13 16:16:18 -05:00
|
|
|
}
|
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
|
2010-11-06 12:40:18 -04:00
|
|
|
bool p3Peers::getGPGDetails(const std::string &id, RsPeerDetails &d)
|
2010-01-13 16:08:46 -05:00
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
2010-02-07 18:01:18 -05:00
|
|
|
std::cerr << "p3Peers::getPgpDetails() called for id : " << id << std::endl;
|
2010-01-13 16:08:46 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* get from mAuthMgr */
|
2010-01-13 16:22:52 -05:00
|
|
|
return AuthGPG::getAuthGPG()->getGPGDetails(id, d);
|
2010-01-13 16:08:46 -05:00
|
|
|
}
|
|
|
|
|
2010-01-13 16:22:52 -05:00
|
|
|
std::string p3Peers::getGPGOwnId()
|
2009-05-23 11:07:35 -04:00
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
2010-02-07 18:01:18 -05:00
|
|
|
std::cerr << "p3Peers::getPGPOwnId()" << std::endl;
|
2009-05-23 11:07:35 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* get from mAuthMgr */
|
2010-01-13 16:22:52 -05:00
|
|
|
return AuthGPG::getAuthGPG()->getGPGOwnId();
|
2009-05-23 11:07:35 -04:00
|
|
|
}
|
|
|
|
|
2010-11-06 12:40:18 -04:00
|
|
|
std::string p3Peers::getGPGId(const std::string &sslid_or_gpgid)
|
2010-01-13 16:11:02 -05:00
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
2010-02-07 18:01:18 -05:00
|
|
|
std::cerr << "p3Peers::getPGPId()" << std::endl;
|
2010-01-13 16:11:02 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* get from mAuthMgr */
|
2010-01-13 16:25:18 -05:00
|
|
|
if (sslid_or_gpgid == AuthSSL::getAuthSSL()->OwnId()) {
|
2010-01-13 16:22:52 -05:00
|
|
|
return AuthGPG::getAuthGPG()->getGPGOwnId();
|
|
|
|
}
|
2011-07-09 14:39:34 -04:00
|
|
|
peerState pcs;
|
|
|
|
if (mPeerMgr->getFriendNetStatus(sslid_or_gpgid, pcs) || mPeerMgr->getOthersNetStatus(sslid_or_gpgid, pcs)) {
|
2010-01-13 16:22:52 -05:00
|
|
|
return pcs.gpg_id;
|
|
|
|
} else {
|
2010-01-13 16:33:54 -05:00
|
|
|
if ( AuthGPG::getAuthGPG()->isGPGId(sslid_or_gpgid)) {
|
2010-01-13 16:25:18 -05:00
|
|
|
#ifdef P3PEERS_DEBUG
|
2010-02-07 18:01:18 -05:00
|
|
|
std::cerr << "p3Peers::getPGPId() given id is already an gpg id : " << sslid_or_gpgid << std::endl;
|
2010-01-13 16:25:18 -05:00
|
|
|
#endif
|
|
|
|
return sslid_or_gpgid;
|
|
|
|
}
|
2010-01-13 16:22:52 -05:00
|
|
|
}
|
2010-01-13 16:25:18 -05:00
|
|
|
return "";
|
2010-01-13 16:11:02 -05:00
|
|
|
}
|
2009-05-23 11:07:35 -04:00
|
|
|
|
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
/* 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
|
|
|
|
*/
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
/* Add/Remove Friends */
|
2011-08-07 17:11:00 -04:00
|
|
|
bool p3Peers::addFriend(const std::string &ssl_id, const std::string &gpg_id)
|
2008-01-25 02:58:29 -05:00
|
|
|
{
|
2011-08-07 17:11:00 -04:00
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
#ifdef P3PEERS_DEBUG
|
2010-01-13 16:22:52 -05:00
|
|
|
std::cerr << "p3Peers::addFriend() with : id : " << id << "; gpg_id : " << gpg_id << std::endl;
|
|
|
|
#endif
|
2011-08-07 17:11:00 -04:00
|
|
|
if (AuthGPG::getAuthGPG()->isGPGId(gpg_id))
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::addFriend() Authorising GPG Id: " << gpg_id << std::endl;
|
|
|
|
#endif
|
|
|
|
if (AuthGPG::getAuthGPG()->AllowConnection(gpg_id, true))
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::addFriend() Authorization OK." << std::endl;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::addFriend() Authorization FAILED." << std::endl;
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::addFriend() Bad gpg_id : " << gpg_id << std::endl;
|
|
|
|
#endif
|
|
|
|
return 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;
|
|
|
|
}
|
|
|
|
|
2011-08-08 07:27:40 -04:00
|
|
|
/* otherwise - we install as ssl_id.....
|
|
|
|
* If we are adding an SSL certificate. we flag lastcontact as now.
|
|
|
|
* This will cause the SSL certificate to be retained for 30 days... and give the person a chance to connect!
|
|
|
|
* */
|
|
|
|
time_t now = time(NULL);
|
|
|
|
return mPeerMgr->addFriend(ssl_id, gpg_id, RS_NET_MODE_UDP, RS_VIS_STATE_STD, now);
|
2010-01-13 16:22:52 -05:00
|
|
|
}
|
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool p3Peers::removeFriendLocation(const std::string &sslId)
|
2010-01-13 16:22:52 -05:00
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
2011-08-07 17:11:00 -04:00
|
|
|
std::cerr << "p3Peers::removeFriendLocation() " << sslId << std::endl;
|
2008-01-25 02:58:29 -05:00
|
|
|
#endif
|
2011-08-07 17:11:00 -04:00
|
|
|
//will remove if it's a ssl id
|
|
|
|
mPeerMgr->removeFriend(sslId);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool p3Peers::removeFriend(const std::string &gpgId)
|
|
|
|
{
|
2010-01-13 16:25:18 -05:00
|
|
|
#ifdef P3PEERS_DEBUG
|
2011-08-07 17:11:00 -04:00
|
|
|
std::cerr << "p3Peers::removeFriend() " << gpgId << std::endl;
|
2010-01-13 16:25:18 -05:00
|
|
|
#endif
|
2011-08-07 17:11:00 -04:00
|
|
|
if (gpgId == AuthGPG::getAuthGPG()->getGPGOwnId()) {
|
|
|
|
std::cerr << "p3Peers::removeFriend() ERROR we're not going to remove our own GPG id." << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
if (AuthGPG::getAuthGPG()->isGPGId(gpgId))
|
|
|
|
{
|
2010-01-13 16:33:54 -05:00
|
|
|
#ifdef P3PEERS_DEBUG
|
2011-08-07 17:11:00 -04:00
|
|
|
std::cerr << "p3Peers::removeFriend() Removing GPG Id: " << gpgId << std::endl;
|
2010-01-13 16:33:54 -05:00
|
|
|
#endif
|
2011-08-07 17:11:00 -04:00
|
|
|
if (AuthGPG::getAuthGPG()->AllowConnection(gpgId, false))
|
|
|
|
{
|
2010-01-13 16:33:54 -05:00
|
|
|
#ifdef P3PEERS_DEBUG
|
2011-08-07 17:11:00 -04:00
|
|
|
std::cerr << "p3Peers::removeFriend() OK." << std::endl;
|
2010-01-13 16:33:54 -05:00
|
|
|
#endif
|
2011-08-07 17:11:00 -04:00
|
|
|
mPeerMgr->removeAllFriendLocations(gpgId);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-01-25 02:58:29 -05:00
|
|
|
#ifdef P3PEERS_DEBUG
|
2011-08-07 17:11:00 -04:00
|
|
|
std::cerr << "p3Peers::removeFriend() FAILED." << std::endl;
|
2010-01-15 16:09:25 -05:00
|
|
|
#endif
|
2011-08-07 17:11:00 -04:00
|
|
|
mPeerMgr->removeAllFriendLocations(gpgId);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-01-15 16:09:25 -05:00
|
|
|
#ifdef P3PEERS_DEBUG
|
2011-08-07 17:11:00 -04:00
|
|
|
std::cerr << "p3Peers::removeFriend() Not GPG Id: " << gpg_id << std::endl;
|
2008-01-25 02:58:29 -05:00
|
|
|
#endif
|
2011-08-07 17:11:00 -04:00
|
|
|
return removeFriendLocation(gpgId);
|
|
|
|
}
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
return false;
|
2008-01-25 02:58:29 -05:00
|
|
|
}
|
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
/* Network Stuff */
|
2010-11-06 12:40:18 -04:00
|
|
|
bool p3Peers::connectAttempt(const std::string &id)
|
2008-01-25 02:58:29 -05:00
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
2010-02-07 18:01:18 -05:00
|
|
|
std::cerr << "p3Peers::connectAttempt() " << id << std::endl;
|
2008-01-25 02:58:29 -05:00
|
|
|
#endif
|
|
|
|
|
2011-07-09 14:39:34 -04:00
|
|
|
return mLinkMgr->retryConnect(id);
|
2008-01-25 02:58:29 -05:00
|
|
|
}
|
|
|
|
|
2009-04-05 09:04:18 -04:00
|
|
|
void p3Peers::getIPServersList(std::list<std::string>& ip_servers)
|
|
|
|
{
|
2011-07-09 14:39:34 -04:00
|
|
|
mNetMgr->getIPServersList(ip_servers) ;
|
2009-04-05 09:04:18 -04:00
|
|
|
}
|
|
|
|
void p3Peers::allowServerIPDetermination(bool b)
|
|
|
|
{
|
2011-07-09 14:39:34 -04:00
|
|
|
mNetMgr->setIPServersEnabled(b) ;
|
2009-04-05 09:04:18 -04:00
|
|
|
}
|
2009-12-13 16:59:26 -05:00
|
|
|
|
|
|
|
void p3Peers::allowTunnelConnection(bool b)
|
|
|
|
{
|
2010-02-07 18:01:18 -05:00
|
|
|
#ifdef P3PEERS_DEBUG
|
2009-12-13 16:59:26 -05:00
|
|
|
std::cerr << "p3Peers::allowTunnelConnection() set tunnel to : " << b << std::endl;
|
2010-02-07 18:01:18 -05:00
|
|
|
#endif
|
2011-07-09 14:39:34 -04:00
|
|
|
mLinkMgr->setTunnelConnection(b) ;
|
2009-12-13 16:59:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool p3Peers::getAllowServerIPDetermination()
|
2009-04-05 09:04:18 -04:00
|
|
|
{
|
2011-07-09 14:39:34 -04:00
|
|
|
return mNetMgr->getIPServersEnabled() ;
|
2009-04-05 09:04:18 -04:00
|
|
|
}
|
|
|
|
|
2009-12-13 16:59:26 -05:00
|
|
|
bool p3Peers::getAllowTunnelConnection()
|
|
|
|
{
|
2010-02-07 18:01:18 -05:00
|
|
|
#ifdef P3PEERS_DEBUG
|
2009-12-13 16:59:26 -05:00
|
|
|
std::cerr << "p3Peers::getAllowTunnelConnection() tunnel is : " << mConnMgr->getTunnelConnection() << std::endl;
|
2010-02-07 18:01:18 -05:00
|
|
|
#endif
|
2011-07-09 14:39:34 -04:00
|
|
|
return mLinkMgr->getTunnelConnection() ;
|
2009-12-13 16:59:26 -05:00
|
|
|
}
|
|
|
|
|
2010-11-06 12:40:18 -04:00
|
|
|
bool p3Peers::setLocalAddress(const std::string &id, const std::string &addr_str, uint16_t port)
|
2008-01-25 02:58:29 -05:00
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
2010-02-07 18:01:18 -05:00
|
|
|
std::cerr << "p3Peers::setLocalAddress() " << id << std::endl;
|
2008-01-25 02:58:29 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
struct sockaddr_in addr;
|
|
|
|
addr.sin_family = AF_INET;
|
|
|
|
addr.sin_port = htons(port);
|
|
|
|
|
|
|
|
int ret = 1;
|
|
|
|
/********************************** WINDOWS/UNIX SPECIFIC PART *******************/
|
|
|
|
#ifndef WINDOWS_SYS
|
|
|
|
if (ret && (0 != inet_aton(addr_str.c_str(), &(addr.sin_addr))))
|
|
|
|
#else
|
|
|
|
addr.sin_addr.s_addr = inet_addr(addr_str.c_str());
|
|
|
|
if (ret)
|
|
|
|
#endif
|
|
|
|
/********************************** WINDOWS/UNIX SPECIFIC PART *******************/
|
|
|
|
{
|
2011-07-09 14:39:34 -04:00
|
|
|
return mPeerMgr->setLocalAddress(id, addr);
|
2008-01-25 02:58:29 -05:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-11-06 12:40:18 -04:00
|
|
|
bool p3Peers::setLocation(const std::string &ssl_id, const std::string &location)
|
2010-01-13 16:22:52 -05:00
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
2010-02-07 18:01:18 -05:00
|
|
|
std::cerr << "p3Peers::setLocation() " << ssl_id << std::endl;
|
2010-01-13 16:22:52 -05:00
|
|
|
#endif
|
|
|
|
|
2011-07-09 14:39:34 -04:00
|
|
|
return mPeerMgr->setLocation(ssl_id, location);
|
2010-01-13 16:22:52 -05:00
|
|
|
}
|
2010-11-06 12:40:18 -04:00
|
|
|
bool p3Peers::setExtAddress(const std::string &id, const std::string &addr_str, uint16_t port)
|
2008-01-25 02:58:29 -05:00
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
2010-02-07 18:01:18 -05:00
|
|
|
std::cerr << "p3Peers::setExtAddress() " << id << std::endl;
|
2008-01-25 02:58:29 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
struct sockaddr_in addr;
|
|
|
|
addr.sin_family = AF_INET;
|
|
|
|
addr.sin_port = htons(port);
|
|
|
|
|
|
|
|
int ret = 1;
|
|
|
|
/********************************** WINDOWS/UNIX SPECIFIC PART *******************/
|
|
|
|
#ifndef WINDOWS_SYS
|
|
|
|
if (ret && (0 != inet_aton(addr_str.c_str(), &(addr.sin_addr))))
|
|
|
|
#else
|
|
|
|
addr.sin_addr.s_addr = inet_addr(addr_str.c_str());
|
|
|
|
if (ret)
|
|
|
|
#endif
|
|
|
|
/********************************** WINDOWS/UNIX SPECIFIC PART *******************/
|
|
|
|
{
|
2011-07-09 14:39:34 -04:00
|
|
|
return mPeerMgr->setExtAddress(id, addr);
|
2008-01-25 02:58:29 -05:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-11-06 12:40:18 -04:00
|
|
|
bool p3Peers::setDynDNS(const std::string &id, const std::string &dyndns)
|
2010-04-22 14:49:08 -04:00
|
|
|
{
|
2010-04-22 14:49:51 -04:00
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::setDynDNS() called with id: " << id << " dyndns: " << dyndns <<std::endl;
|
|
|
|
#endif
|
2011-07-09 14:39:34 -04:00
|
|
|
return mPeerMgr->setDynDNS(id, dyndns);
|
2010-04-22 14:49:08 -04:00
|
|
|
}
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2010-11-06 12:40:18 -04:00
|
|
|
bool p3Peers::setNetworkMode(const std::string &id, uint32_t extNetMode)
|
2008-01-25 02:58:29 -05:00
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
2010-02-07 18:01:18 -05:00
|
|
|
std::cerr << "p3Peers::setNetworkMode() " << id << std::endl;
|
2008-01-25 02:58:29 -05:00
|
|
|
#endif
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
/* translate */
|
|
|
|
uint32_t netMode = 0;
|
|
|
|
switch(extNetMode)
|
|
|
|
{
|
|
|
|
case RS_NETMODE_EXT:
|
|
|
|
netMode = RS_NET_MODE_EXT;
|
|
|
|
break;
|
|
|
|
case RS_NETMODE_UPNP:
|
|
|
|
netMode = RS_NET_MODE_UPNP;
|
|
|
|
break;
|
2008-02-26 11:14:13 -05:00
|
|
|
case RS_NETMODE_UDP:
|
|
|
|
netMode = RS_NET_MODE_UDP;
|
|
|
|
break;
|
2008-02-28 10:58:54 -05:00
|
|
|
case RS_NETMODE_UNREACHABLE:
|
|
|
|
netMode = RS_NET_MODE_UNREACHABLE;
|
|
|
|
break;
|
2008-02-26 11:14:13 -05:00
|
|
|
default:
|
|
|
|
break;
|
2008-02-07 11:18:34 -05:00
|
|
|
}
|
|
|
|
|
2011-07-09 14:39:34 -04:00
|
|
|
return mPeerMgr->setNetworkMode(id, netMode);
|
2008-01-25 02:58:29 -05:00
|
|
|
}
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
|
2009-03-18 15:33:30 -04:00
|
|
|
bool
|
2010-11-06 12:40:18 -04:00
|
|
|
p3Peers::setVisState(const std::string &id, uint32_t extVisState)
|
2008-02-07 11:18:34 -05:00
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
2010-02-07 18:01:18 -05:00
|
|
|
std::cerr << "p3Peers::setVisState() " << id << std::endl;
|
2008-02-07 11:18:34 -05:00
|
|
|
#endif
|
2010-10-31 09:53:28 -04:00
|
|
|
std::cerr << "p3Peers::setVisState() " << id << " " << extVisState << std::endl;
|
2008-02-07 11:18:34 -05:00
|
|
|
|
|
|
|
uint32_t visState = 0;
|
|
|
|
if (!(extVisState & RS_VS_DHT_ON))
|
|
|
|
visState |= RS_VIS_STATE_NODHT;
|
|
|
|
if (!(extVisState & RS_VS_DISC_ON))
|
|
|
|
visState |= RS_VIS_STATE_NODISC;
|
|
|
|
|
2011-07-09 14:39:34 -04:00
|
|
|
return mPeerMgr->setVisState(id, visState);
|
2008-02-07 11:18:34 -05:00
|
|
|
}
|
|
|
|
|
2009-03-18 15:33:30 -04:00
|
|
|
//===========================================================================
|
2008-01-25 02:58:29 -05:00
|
|
|
/* Auth Stuff */
|
2009-03-18 15:33:30 -04:00
|
|
|
std::string
|
2011-07-01 16:47:58 -04:00
|
|
|
p3Peers::GetRetroshareInvite(bool include_signatures)
|
2010-09-03 15:23:24 -04:00
|
|
|
{
|
2011-07-01 16:47:58 -04:00
|
|
|
return GetRetroshareInvite(getOwnId(),include_signatures);
|
2010-09-03 15:23:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
2011-07-01 16:47:58 -04:00
|
|
|
p3Peers::GetRetroshareInvite(const std::string& ssl_id,bool include_signatures)
|
2008-01-25 02:58:29 -05:00
|
|
|
{
|
2010-02-07 18:01:18 -05:00
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::GetRetroshareInvite()" << std::endl;
|
|
|
|
#endif
|
2009-02-08 09:30:28 -05:00
|
|
|
|
2010-01-13 16:29:21 -05:00
|
|
|
//add the sslid, location, ip local and external address after the signature
|
2010-09-03 15:23:24 -04:00
|
|
|
RsPeerDetails Detail;
|
|
|
|
std::string invite ;
|
|
|
|
|
|
|
|
if (getPeerDetails(ssl_id, Detail))
|
|
|
|
{
|
2011-07-01 16:47:58 -04:00
|
|
|
invite = AuthGPG::getAuthGPG()->SaveCertificateToString(Detail.gpg_id,include_signatures);
|
2010-09-03 15:23:24 -04:00
|
|
|
|
|
|
|
if(!Detail.isOnlyGPGdetail)
|
|
|
|
{
|
|
|
|
invite += CERT_SSL_ID + Detail.id + ";";
|
|
|
|
invite += CERT_LOCATION + Detail.location + ";\n";
|
|
|
|
invite += CERT_LOCAL_IP + Detail.localAddr + ":";
|
|
|
|
std::ostringstream out;
|
|
|
|
out << Detail.localPort;
|
|
|
|
invite += out.str() + ";";
|
|
|
|
invite += CERT_EXT_IP + Detail.extAddr + ":";
|
|
|
|
std::ostringstream out2;
|
|
|
|
out2 << Detail.extPort;
|
|
|
|
invite += out2.str() + ";";
|
|
|
|
if (!Detail.dyndns.empty()) {
|
|
|
|
invite += "\n" + CERT_DYNDNS + Detail.dyndns + ";";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2010-02-07 18:01:18 -05:00
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::GetRetroshareInvite() returns : \n" << invite << std::endl;
|
|
|
|
#endif
|
2010-01-13 16:29:21 -05:00
|
|
|
return invite;
|
2008-01-25 02:58:29 -05:00
|
|
|
}
|
|
|
|
|
2009-03-18 15:33:30 -04:00
|
|
|
//===========================================================================
|
|
|
|
|
2011-08-12 09:42:30 -04:00
|
|
|
bool p3Peers::loadCertificateFromFile(const std::string &/*fname*/, std::string &/*id*/, std::string &/*gpg_id*/)
|
2008-01-25 02:58:29 -05:00
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
2010-01-13 16:22:52 -05:00
|
|
|
std::cerr << "p3Peers::LoadCertificateFromFile() not implemented yet";
|
2008-01-25 02:58:29 -05:00
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2010-01-13 16:22:52 -05:00
|
|
|
return false;
|
2008-01-25 02:58:29 -05:00
|
|
|
}
|
|
|
|
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2010-01-13 16:29:21 -05:00
|
|
|
//bool splitCerts(std::string in, std::string &sslcert, std::string &pgpcert)
|
|
|
|
//{
|
|
|
|
// std::cerr << "splitCerts():" << in;
|
|
|
|
// std::cerr << std::endl;
|
|
|
|
//
|
|
|
|
// /* search for -----END CERTIFICATE----- */
|
|
|
|
// std::string sslend("-----END CERTIFICATE-----");
|
|
|
|
// std::string pgpend("-----END PGP PUBLIC KEY BLOCK-----");
|
|
|
|
// size_t pos = in.find(sslend);
|
|
|
|
// size_t pos2 = in.find(pgpend);
|
|
|
|
// size_t ssllen, pgplen;
|
|
|
|
//
|
|
|
|
// if (pos != std::string::npos)
|
|
|
|
// {
|
|
|
|
// std::cerr << "splitCerts(): Found SSL Cert";
|
|
|
|
// std::cerr << std::endl;
|
|
|
|
//
|
|
|
|
// ssllen = pos + sslend.length();
|
|
|
|
// sslcert = in.substr(0, ssllen);
|
|
|
|
//
|
|
|
|
// if (pos2 != std::string::npos)
|
|
|
|
// {
|
|
|
|
// std::cerr << "splitCerts(): Found SSL + PGP Cert";
|
|
|
|
// std::cerr << std::endl;
|
|
|
|
//
|
|
|
|
// pgplen = pos2 + pgpend.length() - ssllen;
|
|
|
|
// pgpcert = in.substr(ssllen, pgplen);
|
|
|
|
// }
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
// else if (pos2 != std::string::npos)
|
|
|
|
// {
|
|
|
|
// std::cerr << "splitCerts(): Found PGP Cert Only";
|
|
|
|
// std::cerr << std::endl;
|
|
|
|
//
|
|
|
|
// pgplen = pos2 + pgpend.length();
|
|
|
|
// pgpcert = in.substr(0, pgplen);
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
// return false;
|
|
|
|
//}
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2011-04-08 14:53:12 -04:00
|
|
|
static bool splitCert(const std::string &certstr, std::string &cert, std::string &peerInfo)
|
|
|
|
{
|
|
|
|
cert.erase();
|
|
|
|
peerInfo.erase();
|
|
|
|
|
|
|
|
/* search for -----END CERTIFICATE----- */
|
|
|
|
std::string pgpend("-----END PGP PUBLIC KEY BLOCK-----");
|
|
|
|
|
|
|
|
size_t pos = certstr.find(pgpend);
|
|
|
|
|
|
|
|
if (pos != std::string::npos) {
|
|
|
|
pos += pgpend.length();
|
|
|
|
cert = certstr.substr(0, pos);
|
|
|
|
peerInfo = certstr.substr(pos + 1);
|
|
|
|
}
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2011-04-08 14:53:12 -04:00
|
|
|
return !cert.empty();
|
|
|
|
}
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2011-03-15 19:15:46 -04:00
|
|
|
bool p3Peers::loadDetailsFromStringCert(const std::string &certstr, RsPeerDetails &pd,std::string& error_string)
|
2008-01-25 02:58:29 -05:00
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::LoadCertificateFromString() ";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2010-01-13 16:29:21 -05:00
|
|
|
//parse the text to get ip address
|
|
|
|
try {
|
|
|
|
|
2011-04-08 14:53:12 -04:00
|
|
|
std::string cert;
|
|
|
|
std::string peerInfo;
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2011-04-08 14:53:12 -04:00
|
|
|
if (splitCert(certstr, cert, peerInfo)) {
|
2010-01-13 16:29:21 -05:00
|
|
|
std::string gpg_id;
|
2011-04-08 14:53:12 -04:00
|
|
|
AuthGPG::getAuthGPG()->LoadCertificateFromString(cert, gpg_id,error_string);
|
2010-01-13 16:29:21 -05:00
|
|
|
AuthGPG::getAuthGPG()->getGPGDetails(gpg_id, pd);
|
2011-04-08 14:53:12 -04:00
|
|
|
if (gpg_id.empty()) {
|
2010-01-13 16:29:21 -05:00
|
|
|
return false;
|
|
|
|
}
|
2011-04-08 14:53:12 -04:00
|
|
|
} else {
|
|
|
|
return false;
|
2010-01-13 16:22:52 -05:00
|
|
|
}
|
2010-01-13 16:29:21 -05:00
|
|
|
|
2010-02-08 09:06:43 -05:00
|
|
|
#ifdef P3PEERS_DEBUG
|
2010-01-13 16:29:21 -05:00
|
|
|
std::cerr << "Parsing cert for sslid, location, ext and local address details. : " << certstr << std::endl;
|
2010-02-08 09:06:43 -05:00
|
|
|
#endif
|
2010-01-13 16:29:21 -05:00
|
|
|
|
|
|
|
//let's parse the ssl id
|
2011-04-08 14:53:12 -04:00
|
|
|
size_t parsePosition = peerInfo.find(CERT_SSL_ID);
|
2010-01-13 16:29:21 -05:00
|
|
|
std::cerr << "sslid position : " << parsePosition << std::endl;
|
2010-01-13 16:30:44 -05:00
|
|
|
if (parsePosition != std::string::npos) {
|
|
|
|
parsePosition += CERT_SSL_ID.length();
|
2011-04-08 14:53:12 -04:00
|
|
|
std::string subCert = peerInfo.substr(parsePosition);
|
2010-01-13 16:30:44 -05:00
|
|
|
parsePosition = subCert.find(";");
|
|
|
|
if (parsePosition != std::string::npos) {
|
|
|
|
std::string ssl_id = subCert.substr(0, parsePosition);
|
|
|
|
std::cerr << "SSL id : " << ssl_id << std::endl;
|
|
|
|
pd.id = ssl_id;
|
2010-02-26 18:43:40 -05:00
|
|
|
pd.isOnlyGPGdetail = false;
|
2010-01-13 16:30:44 -05:00
|
|
|
}
|
|
|
|
}
|
2010-01-13 16:29:21 -05:00
|
|
|
|
|
|
|
//let's parse the location
|
2011-04-08 14:53:12 -04:00
|
|
|
parsePosition = peerInfo.find(CERT_LOCATION);
|
2010-01-13 16:29:21 -05:00
|
|
|
std::cerr << "location position : " << parsePosition << std::endl;
|
2010-01-13 16:30:44 -05:00
|
|
|
if (parsePosition != std::string::npos) {
|
|
|
|
parsePosition += CERT_LOCATION.length();
|
2011-04-08 14:53:12 -04:00
|
|
|
std::string subCert = peerInfo.substr(parsePosition);
|
2010-01-13 16:30:44 -05:00
|
|
|
parsePosition = subCert.find(";");
|
|
|
|
if (parsePosition != std::string::npos) {
|
|
|
|
std::string location = subCert.substr(0, parsePosition);
|
|
|
|
std::cerr << "location : " << location << std::endl;
|
|
|
|
pd.location = location;
|
|
|
|
}
|
|
|
|
}
|
2010-01-13 16:29:21 -05:00
|
|
|
|
|
|
|
//let's parse ip local address
|
2011-04-08 14:53:12 -04:00
|
|
|
parsePosition = peerInfo.find(CERT_LOCAL_IP);
|
2010-01-13 16:29:21 -05:00
|
|
|
std::cerr << "local ip position : " << parsePosition << std::endl;
|
2010-01-13 16:30:44 -05:00
|
|
|
if (parsePosition != std::string::npos) {
|
|
|
|
parsePosition += CERT_LOCAL_IP.length();
|
2011-04-08 14:53:12 -04:00
|
|
|
std::string subCert = peerInfo.substr(parsePosition);
|
2010-01-13 16:30:44 -05:00
|
|
|
parsePosition = subCert.find(":");
|
|
|
|
if (parsePosition != std::string::npos) {
|
|
|
|
std::string local_ip = subCert.substr(0, parsePosition);
|
|
|
|
std::cerr << "Local Ip : " << local_ip << std::endl;
|
|
|
|
pd.localAddr = local_ip;
|
|
|
|
|
|
|
|
//let's parse local port
|
|
|
|
subCert = subCert.substr(parsePosition + 1);
|
|
|
|
parsePosition = subCert.find(";");
|
|
|
|
if (parsePosition != std::string::npos) {
|
|
|
|
std::string local_port = subCert.substr(0, parsePosition);
|
|
|
|
std::cerr << "Local port : " << local_port << std::endl;
|
2010-01-13 19:35:16 -05:00
|
|
|
std::istringstream instream(local_port);
|
|
|
|
uint16_t local_port_int;
|
|
|
|
instream >> local_port_int;
|
|
|
|
pd.localPort = (local_port_int);
|
2010-01-13 16:30:44 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-01-13 16:29:21 -05:00
|
|
|
|
|
|
|
//let's parse ip ext address
|
2011-04-08 14:53:12 -04:00
|
|
|
parsePosition = peerInfo.find(CERT_EXT_IP);
|
2010-01-13 16:29:21 -05:00
|
|
|
std::cerr << "Ext ip position : " << parsePosition << std::endl;
|
2010-01-13 16:30:44 -05:00
|
|
|
if (parsePosition != std::string::npos) {
|
|
|
|
parsePosition = parsePosition + CERT_EXT_IP.length();
|
2011-04-08 14:53:12 -04:00
|
|
|
std::string subCert = peerInfo.substr(parsePosition);
|
2010-01-13 16:30:44 -05:00
|
|
|
parsePosition = subCert.find(":");
|
|
|
|
if (parsePosition != std::string::npos) {
|
|
|
|
std::string ext_ip = subCert.substr(0, parsePosition);
|
|
|
|
std::cerr << "Ext Ip : " << ext_ip << std::endl;
|
|
|
|
pd.extAddr = ext_ip;
|
|
|
|
|
|
|
|
//let's parse ext port
|
|
|
|
subCert = subCert.substr(parsePosition + 1);
|
|
|
|
parsePosition = subCert.find(";");
|
|
|
|
if (parsePosition != std::string::npos) {
|
|
|
|
std::string ext_port = subCert.substr(0, parsePosition);
|
|
|
|
std::cerr << "Ext port : " << ext_port << std::endl;
|
2010-01-13 19:35:16 -05:00
|
|
|
std::istringstream instream(ext_port);
|
|
|
|
uint16_t ext_port_int;
|
|
|
|
instream >> ext_port_int;
|
|
|
|
pd.extPort = (ext_port_int);
|
2010-01-13 16:30:44 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-22 14:49:08 -04:00
|
|
|
//let's parse DynDNS
|
2011-04-08 14:53:12 -04:00
|
|
|
parsePosition = peerInfo.find(CERT_DYNDNS);
|
2010-04-22 14:49:08 -04:00
|
|
|
std::cerr << "location DynDNS : " << parsePosition << std::endl;
|
|
|
|
if (parsePosition != std::string::npos) {
|
|
|
|
parsePosition += CERT_DYNDNS.length();
|
2011-04-08 14:53:12 -04:00
|
|
|
std::string subCert = peerInfo.substr(parsePosition);
|
2010-04-22 14:49:08 -04:00
|
|
|
parsePosition = subCert.find(";");
|
|
|
|
if (parsePosition != std::string::npos) {
|
|
|
|
std::string DynDNS = subCert.substr(0, parsePosition);
|
|
|
|
std::cerr << "DynDNS : " << DynDNS << std::endl;
|
|
|
|
pd.dyndns = DynDNS;
|
|
|
|
}
|
|
|
|
}
|
2010-01-13 16:29:21 -05:00
|
|
|
|
|
|
|
} catch (...) {
|
|
|
|
std::cerr << "ConnectFriendWizard : Parse ip address error." << std::endl;
|
2010-01-13 16:22:52 -05:00
|
|
|
}
|
2010-01-13 16:29:21 -05:00
|
|
|
|
2010-04-19 07:58:34 -04:00
|
|
|
if (pd.gpg_id == "") {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
2008-01-25 02:58:29 -05:00
|
|
|
}
|
|
|
|
|
2011-04-08 14:53:12 -04:00
|
|
|
bool p3Peers::cleanCertificate(const std::string &certstr, std::string &cleanCert)
|
|
|
|
{
|
|
|
|
std::string cert;
|
|
|
|
std::string peerInfo;
|
|
|
|
|
|
|
|
if (splitCert(certstr, cert, peerInfo)) {
|
|
|
|
cleanCert = cleanUpCertificate(cert);
|
|
|
|
if (!cleanCert.empty()) {
|
|
|
|
if (!peerInfo.empty()) {
|
|
|
|
if (*cleanCert.rbegin() != '\n') {
|
|
|
|
cleanCert += "\n";
|
|
|
|
}
|
|
|
|
cleanCert += peerInfo;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2011-04-08 14:53:12 -04:00
|
|
|
return false;
|
|
|
|
}
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2011-08-12 09:42:30 -04:00
|
|
|
bool p3Peers::saveCertificateToFile(const std::string &id, const std::string &/*fname*/)
|
2008-01-25 02:58:29 -05:00
|
|
|
{
|
2011-08-12 09:42:30 -04:00
|
|
|
/* remove unused parameter warnings */
|
|
|
|
(void) id;
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
#ifdef P3PEERS_DEBUG
|
2010-01-13 16:22:52 -05:00
|
|
|
std::cerr << "p3Peers::SaveCertificateToFile() not implemented yet " << id;
|
2008-01-25 02:58:29 -05:00
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2010-01-13 16:22:52 -05:00
|
|
|
// ensureExtension(fname, "pqi");
|
|
|
|
//
|
|
|
|
// return AuthSSL::getAuthSSL()->SaveCertificateToFile(id, fname);
|
|
|
|
return false;
|
2008-01-25 02:58:29 -05:00
|
|
|
}
|
|
|
|
|
2010-11-06 12:40:18 -04:00
|
|
|
std::string p3Peers::saveCertificateToString(const std::string &id)
|
2008-01-25 02:58:29 -05:00
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::SaveCertificateToString() " << id;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2010-01-13 16:22:52 -05:00
|
|
|
if (id == AuthSSL::getAuthSSL()->OwnId()) {
|
|
|
|
return AuthSSL::getAuthSSL()->SaveOwnCertificateToString();
|
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
2008-01-25 02:58:29 -05:00
|
|
|
}
|
|
|
|
|
2010-11-06 12:40:18 -04:00
|
|
|
bool p3Peers::signGPGCertificate(const std::string &id)
|
2008-01-25 02:58:29 -05:00
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::SignCertificate() " << id;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2010-02-09 14:10:42 -05:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
AuthGPG::getAuthGPG()->AllowConnection(id, true);
|
2010-02-09 14:10:42 -05:00
|
|
|
return AuthGPG::getAuthGPG()->SignCertificateLevel0(id);
|
2010-01-13 16:22:52 -05:00
|
|
|
}
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2010-11-06 12:40:18 -04:00
|
|
|
bool p3Peers::trustGPGCertificate(const std::string &id, uint32_t trustlvl)
|
2008-01-25 02:58:29 -05:00
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::TrustCertificate() " << id;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2010-01-13 16:14:49 -05:00
|
|
|
//check if we've got a ssl or gpg id
|
2010-12-21 16:13:08 -05:00
|
|
|
std::string gpgId = getGPGId(id);
|
|
|
|
if (gpgId.empty()) {
|
2010-01-13 16:14:49 -05:00
|
|
|
//if no result then it must be a gpg id
|
|
|
|
return AuthGPG::getAuthGPG()->TrustCertificate(id, trustlvl);
|
|
|
|
} else {
|
2010-12-21 16:13:08 -05:00
|
|
|
return AuthGPG::getAuthGPG()->TrustCertificate(gpgId, trustlvl);
|
2010-01-13 16:14:49 -05:00
|
|
|
}
|
2008-01-25 02:58:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ensureExtension(std::string &name, std::string def_ext)
|
|
|
|
{
|
|
|
|
/* if it has an extension, don't change */
|
|
|
|
int len = name.length();
|
|
|
|
int extpos = name.find_last_of('.');
|
|
|
|
|
|
|
|
std::ostringstream out;
|
|
|
|
out << "ensureExtension() name: " << name << std::endl;
|
|
|
|
out << "\t\t extpos: " << extpos;
|
|
|
|
out << " len: " << len << std::endl;
|
|
|
|
|
|
|
|
/* check that the '.' has between 1 and 4 char after it (an extension) */
|
|
|
|
if ((extpos > 0) && (extpos < len - 1) && (extpos + 6 > len))
|
|
|
|
{
|
|
|
|
/* extension there */
|
|
|
|
std::string curext = name.substr(extpos, len);
|
|
|
|
out << "ensureExtension() curext: " << curext << std::endl;
|
|
|
|
std::cerr << out.str();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (extpos != len - 1)
|
|
|
|
{
|
|
|
|
name += ".";
|
|
|
|
}
|
|
|
|
name += def_ext;
|
|
|
|
|
|
|
|
out << "ensureExtension() added ext: " << name << std::endl;
|
|
|
|
|
|
|
|
std::cerr << out.str();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-09-22 18:37:57 -04:00
|
|
|
/* Group Stuff */
|
|
|
|
bool p3Peers::addGroup(RsGroupInfo &groupInfo)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::addGroup()" << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2011-07-09 14:39:34 -04:00
|
|
|
return mPeerMgr->addGroup(groupInfo);
|
2010-09-22 18:37:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool p3Peers::editGroup(const std::string &groupId, RsGroupInfo &groupInfo)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::editGroup()" << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2011-07-09 14:39:34 -04:00
|
|
|
return mPeerMgr->editGroup(groupId, groupInfo);
|
2010-09-22 18:37:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool p3Peers::removeGroup(const std::string &groupId)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::removeGroup()" << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2011-07-09 14:39:34 -04:00
|
|
|
return mPeerMgr->removeGroup(groupId);
|
2010-09-22 18:37:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool p3Peers::getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::getGroupInfo()" << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2011-07-09 14:39:34 -04:00
|
|
|
return mPeerMgr->getGroupInfo(groupId, groupInfo);
|
2010-09-22 18:37:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool p3Peers::getGroupInfoList(std::list<RsGroupInfo> &groupInfoList)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::getGroupInfoList()" << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2011-07-09 14:39:34 -04:00
|
|
|
return mPeerMgr->getGroupInfoList(groupInfoList);
|
2010-09-22 18:37:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool p3Peers::assignPeerToGroup(const std::string &groupId, const std::string &peerId, bool assign)
|
|
|
|
{
|
|
|
|
std::list<std::string> peerIds;
|
|
|
|
peerIds.push_back(peerId);
|
|
|
|
|
|
|
|
return assignPeersToGroup(groupId, peerIds, assign);
|
|
|
|
}
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2010-09-22 18:37:57 -04:00
|
|
|
bool p3Peers::assignPeersToGroup(const std::string &groupId, const std::list<std::string> &peerIds, bool assign)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::assignPeersToGroup()" << std::endl;
|
|
|
|
#endif
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2011-07-09 14:39:34 -04:00
|
|
|
return mPeerMgr->assignPeersToGroup(groupId, peerIds, assign);
|
2010-09-22 18:37:57 -04:00
|
|
|
}
|
2008-01-25 02:58:29 -05:00
|
|
|
|
|
|
|
|
|
|
|
RsPeerDetails::RsPeerDetails()
|
2010-06-05 15:16:39 -04:00
|
|
|
:isOnlyGPGdetail(false),
|
|
|
|
id(""),gpg_id(""),
|
|
|
|
name(""),email(""),location(""),
|
|
|
|
org(""),issuer(""),fpr(""),authcode(""),
|
|
|
|
trustLvl(0), validLvl(0),ownsign(false),
|
|
|
|
hasSignedMe(false),accept_connection(false),
|
|
|
|
state(0),localAddr(""),localPort(0),extAddr(""),extPort(0),netMode(0),visState(0),
|
2011-01-06 13:26:39 -05:00
|
|
|
lastConnect(0),connectState(0),connectStateString(""),connectPeriod(0)
|
2008-01-25 02:58:29 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream &operator<<(std::ostream &out, const RsPeerDetails &detail)
|
|
|
|
{
|
|
|
|
out << "RsPeerDetail: " << detail.name << " <" << detail.id << ">";
|
|
|
|
out << std::endl;
|
|
|
|
|
|
|
|
out << " email: " << detail.email;
|
|
|
|
out << " location:" << detail.location;
|
|
|
|
out << " org: " << detail.org;
|
|
|
|
out << std::endl;
|
|
|
|
|
|
|
|
out << " fpr: " << detail.fpr;
|
|
|
|
out << " authcode:" << detail.authcode;
|
|
|
|
out << std::endl;
|
|
|
|
|
|
|
|
out << " signers:";
|
|
|
|
out << std::endl;
|
|
|
|
|
|
|
|
std::list<std::string>::const_iterator it;
|
2010-01-13 16:11:02 -05:00
|
|
|
for(it = detail.gpgSigners.begin();
|
|
|
|
it != detail.gpgSigners.end(); it++)
|
2008-01-25 02:58:29 -05:00
|
|
|
{
|
|
|
|
out << "\t" << *it;
|
|
|
|
out << std::endl;
|
|
|
|
}
|
|
|
|
out << std::endl;
|
|
|
|
|
|
|
|
out << " trustLvl: " << detail.trustLvl;
|
2010-01-13 16:05:38 -05:00
|
|
|
out << " ownSign: " << detail.ownsign;
|
2008-01-25 02:58:29 -05:00
|
|
|
out << std::endl;
|
|
|
|
|
|
|
|
out << " state: " << detail.state;
|
|
|
|
out << " netMode: " << detail.netMode;
|
|
|
|
out << std::endl;
|
|
|
|
|
|
|
|
out << " localAddr: " << detail.localAddr;
|
|
|
|
out << ":" << detail.localPort;
|
|
|
|
out << std::endl;
|
|
|
|
out << " extAddr: " << detail.extAddr;
|
|
|
|
out << ":" << detail.extPort;
|
|
|
|
out << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
out << " lastConnect: " << detail.lastConnect;
|
|
|
|
out << " connectPeriod: " << detail.connectPeriod;
|
|
|
|
out << std::endl;
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
2010-09-22 18:37:57 -04:00
|
|
|
|
|
|
|
RsGroupInfo::RsGroupInfo()
|
|
|
|
{
|
|
|
|
flag = 0;
|
|
|
|
}
|