2008-01-25 01:36:40 -05:00
|
|
|
/*
|
|
|
|
* libretroshare/src/pqi: pqisslpersongrp.cc
|
|
|
|
*
|
|
|
|
* 3P/PQI network interface for RetroShare.
|
|
|
|
*
|
|
|
|
* Copyright 2004-2008 by Robert Fernie.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License Version 2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-10-01 04:11:15 -04:00
|
|
|
#include "serialiser/rsserviceserialiser.h"
|
2008-07-10 12:29:18 -04:00
|
|
|
#include "util/rsdebug.h"
|
|
|
|
|
2008-01-25 01:36:40 -05:00
|
|
|
#include "pqi/pqisslpersongrp.h"
|
2010-01-13 15:56:55 -05:00
|
|
|
#include "pqi/authssl.h"
|
2008-01-28 00:40:32 -05:00
|
|
|
|
2008-01-25 01:36:40 -05:00
|
|
|
|
|
|
|
const int pqipersongrpzone = 354;
|
|
|
|
|
2008-02-26 21:32:20 -05:00
|
|
|
/****
|
|
|
|
* #define PQI_DISABLE_UDP 1
|
|
|
|
***/
|
|
|
|
|
2008-01-25 01:36:40 -05:00
|
|
|
/********************************** SSL Specific features ***************************/
|
|
|
|
|
|
|
|
#include "pqi/pqissl.h"
|
|
|
|
#include "pqi/pqissllistener.h"
|
2013-09-03 09:35:39 -04:00
|
|
|
#include "pqi/p3peermgr.h"
|
2008-01-25 01:36:40 -05:00
|
|
|
|
2015-04-21 16:09:20 -04:00
|
|
|
//#define PQISSLPERSON_DEBUG
|
2010-06-24 14:06:10 -04:00
|
|
|
|
2008-02-26 21:32:20 -05:00
|
|
|
#ifndef PQI_DISABLE_UDP
|
2008-01-25 01:36:40 -05:00
|
|
|
#include "pqi/pqissludp.h"
|
|
|
|
#endif
|
|
|
|
|
2013-09-03 09:35:39 -04:00
|
|
|
#include "pqi/pqisslproxy.h"
|
2009-12-13 16:59:26 -05:00
|
|
|
|
2013-09-13 10:35:19 -04:00
|
|
|
pqilistener * pqisslpersongrp::locked_createListener(const struct sockaddr_storage &laddr)
|
2008-01-25 01:36:40 -05:00
|
|
|
{
|
2011-07-09 14:39:34 -04:00
|
|
|
pqilistener *listener = new pqissllistener(laddr, mPeerMgr);
|
2008-01-25 01:36:40 -05:00
|
|
|
return listener;
|
|
|
|
}
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
pqiperson * pqisslpersongrp::locked_createPerson(const RsPeerId& id, pqilistener *listener)
|
2008-01-25 01:36:40 -05:00
|
|
|
{
|
2015-04-21 16:09:20 -04:00
|
|
|
#ifdef PQISSLPERSON_DEBUG
|
2013-09-08 22:10:49 -04:00
|
|
|
std::cerr << "pqisslpersongrp::locked_createPerson() PeerId: " << id;
|
2015-04-21 16:09:20 -04:00
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2013-09-08 22:10:49 -04:00
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
pqioutput(PQL_DEBUG_BASIC, pqipersongrpzone, "pqipersongrp::createPerson() PeerId: " + id.toStdString());
|
2008-01-25 01:36:40 -05:00
|
|
|
|
|
|
|
pqiperson *pqip = new pqiperson(id, this);
|
|
|
|
|
2013-09-03 09:35:39 -04:00
|
|
|
// If using proxy, then only create a proxy item, otherwise can use any.
|
2014-01-19 01:25:49 -05:00
|
|
|
// If we are a hidden node - then all connections should be via proxy.
|
|
|
|
if (mPeerMgr->isHiddenPeer(id) || mPeerMgr->isHidden())
|
2013-09-03 09:35:39 -04:00
|
|
|
{
|
2015-04-21 16:09:20 -04:00
|
|
|
#ifdef PQISTREAMER_DEBUG
|
|
|
|
std::cerr << "pqisslpersongrp::locked_createPerson() Is Hidden Peer!";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2008-01-25 01:36:40 -05:00
|
|
|
|
2013-09-03 09:35:39 -04:00
|
|
|
pqisslproxy *pqis = new pqisslproxy((pqissllistener *) listener, pqip, mLinkMgr);
|
|
|
|
|
|
|
|
/* construct the serialiser ....
|
|
|
|
* Needs:
|
|
|
|
* * FileItem
|
|
|
|
* * FileData
|
|
|
|
* * ServiceGeneric
|
|
|
|
*/
|
2009-12-13 16:59:26 -05:00
|
|
|
|
2013-09-03 09:35:39 -04:00
|
|
|
|
|
|
|
RsSerialiser *rss = new RsSerialiser();
|
|
|
|
rss->addSerialType(new RsServiceSerialiser());
|
|
|
|
|
2013-10-01 23:21:04 -04:00
|
|
|
pqiconnect *pqisc = new pqiconnect(pqip, rss, pqis);
|
2013-09-03 09:35:39 -04:00
|
|
|
|
2015-09-07 05:22:15 -04:00
|
|
|
if (mPeerMgr->isHiddenI2P() | mPeerMgr->isHiddenI2PPeer(id))
|
|
|
|
pqip -> addChildInterface(PQI_CONNECT_HIDDEN_I2P_TCP, pqisc);
|
|
|
|
else
|
|
|
|
/* default tor */
|
|
|
|
pqip -> addChildInterface(PQI_CONNECT_HIDDEN_TOR_TCP, pqisc);
|
2013-09-03 09:35:39 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-21 16:09:20 -04:00
|
|
|
#ifdef PQISTREAMER_DEBUG
|
|
|
|
std::cerr << "pqisslpersongrp::locked_createPerson() Is Normal Peer!";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2013-09-08 22:10:49 -04:00
|
|
|
|
2013-09-03 09:35:39 -04:00
|
|
|
pqissl *pqis = new pqissl((pqissllistener *) listener, pqip, mLinkMgr);
|
|
|
|
|
|
|
|
/* construct the serialiser ....
|
|
|
|
* Needs:
|
|
|
|
* * FileItem
|
|
|
|
* * FileData
|
|
|
|
* * ServiceGeneric
|
|
|
|
*/
|
|
|
|
|
|
|
|
ssl_tunnels[id] = pqis ; // keeps for getting crypt info per peer.
|
|
|
|
|
|
|
|
RsSerialiser *rss = new RsSerialiser();
|
|
|
|
rss->addSerialType(new RsServiceSerialiser());
|
|
|
|
|
2013-10-01 23:21:04 -04:00
|
|
|
pqiconnect *pqisc = new pqiconnect(pqip, rss, pqis);
|
2013-09-03 09:35:39 -04:00
|
|
|
|
|
|
|
pqip -> addChildInterface(PQI_CONNECT_TCP, pqisc);
|
|
|
|
|
2008-02-26 21:32:20 -05:00
|
|
|
#ifndef PQI_DISABLE_UDP
|
2013-09-03 09:35:39 -04:00
|
|
|
pqissludp *pqius = new pqissludp(pqip, mLinkMgr);
|
2011-07-09 14:39:34 -04:00
|
|
|
|
2013-09-03 09:35:39 -04:00
|
|
|
RsSerialiser *rss2 = new RsSerialiser();
|
|
|
|
rss2->addSerialType(new RsServiceSerialiser());
|
|
|
|
|
2013-10-01 23:21:04 -04:00
|
|
|
pqiconnect *pqiusc = new pqiconnect(pqip, rss2, pqius);
|
2013-09-03 09:35:39 -04:00
|
|
|
|
|
|
|
// add a ssl + proxy interface.
|
|
|
|
// Add Proxy First.
|
|
|
|
pqip -> addChildInterface(PQI_CONNECT_UDP, pqiusc);
|
2008-01-25 01:36:40 -05:00
|
|
|
#endif
|
2013-09-03 09:35:39 -04:00
|
|
|
}
|
2008-01-25 01:36:40 -05:00
|
|
|
|
2015-06-01 18:03:07 -04:00
|
|
|
return pqip;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pqisslpersongrp::disconnectPeer(const RsPeerId &peer)
|
|
|
|
{
|
|
|
|
std::map<RsPeerId,pqissl*>::iterator it = ssl_tunnels.find(peer) ;
|
|
|
|
|
|
|
|
if(it != ssl_tunnels.end())
|
|
|
|
it->second->disconnect() ;
|
|
|
|
else
|
|
|
|
std::cerr << "pqisslpersongrp::cannot find peer " << peer << ". cannot disconnect!" << std::endl;
|
2008-01-25 01:36:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************** SSL Specific features ***************************/
|
|
|
|
|
|
|
|
|