mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-24 16:51:25 -04:00
Removing old services, serialisers and other references for:
- forums - channels - tunnel - blog - gamelauncher. - distrib. Note this majorly breaks the GUI, for the moment. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.6-initdev@6683 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
212b4c44c9
commit
a6cf738371
47 changed files with 15 additions and 14890 deletions
|
@ -136,7 +136,6 @@ p3LinkMgrIMPL::p3LinkMgrIMPL(p3PeerMgrIMPL *peerMgr, p3NetMgrIMPL *netMgr)
|
|||
{
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
mAllowTunnelConnection = false;
|
||||
mDNSResolver = new DNSResolver();
|
||||
mRetryPeriod = MIN_RETRY_PERIOD;
|
||||
|
||||
|
@ -159,18 +158,6 @@ p3LinkMgrIMPL::p3LinkMgrIMPL(p3PeerMgrIMPL *peerMgr, p3NetMgrIMPL *netMgr)
|
|||
return;
|
||||
}
|
||||
|
||||
void p3LinkMgrIMPL::setTunnelConnection(bool b)
|
||||
{
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
mAllowTunnelConnection = b;
|
||||
}
|
||||
|
||||
bool p3LinkMgrIMPL::getTunnelConnection()
|
||||
{
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
return mAllowTunnelConnection;
|
||||
}
|
||||
|
||||
bool p3LinkMgrIMPL::setLocalAddress(struct sockaddr_in addr)
|
||||
{
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
@ -695,13 +682,6 @@ bool p3LinkMgrIMPL::connectAttempt(const std::string &id, struct sockaddr_in &ra
|
|||
it->second.linkType |= RS_NET_CONN_TRANS_UDP_UNKNOWN;
|
||||
}
|
||||
}
|
||||
else if (type & RS_NET_CONN_TUNNEL)
|
||||
{
|
||||
#ifdef LINKMGR_DEBUG_LINKTYPE
|
||||
std::cerr << "p3LinkMgrIMPL::connectAttempt() type & TUNNEL => TUNNEL" << std::endl;
|
||||
#endif
|
||||
it->second.linkType |= RS_NET_CONN_TRANS_TUNNEL;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef LINKMGR_DEBUG_LINKTYPE
|
||||
|
@ -1529,16 +1509,7 @@ bool p3LinkMgrIMPL::tryConnectUDP(const std::string &id, struct sockaddr_in &r
|
|||
#ifdef LINKMGR_DEBUG
|
||||
std::cerr << "p3LinkMgrIMPL::retryConnectUDP() Peer Already Connected" << std::endl;
|
||||
#endif
|
||||
if (it->second.connecttype & RS_NET_CONN_TUNNEL) {
|
||||
#ifdef LINKMGR_DEBUG
|
||||
std::cerr << "p3LinkMgrIMPL::retryConnectUDP() Peer Connected through a tunnel connection, let's try a normal connection." << std::endl;
|
||||
#endif
|
||||
} else {
|
||||
#ifdef LINKMGR_DEBUG
|
||||
std::cerr << "p3LinkMgrIMPL::retryConnectUDP() Peer Connected no more connection attempts" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Explicit Request to start the UDP connection */
|
||||
|
@ -1614,19 +1585,7 @@ bool p3LinkMgrIMPL::retryConnectTCP(const std::string &id)
|
|||
#ifdef LINKMGR_DEBUG
|
||||
std::cerr << "p3LinkMgrIMPL::retryConnectTCP() Peer Already Connected" << std::endl;
|
||||
#endif
|
||||
if (it->second.connecttype & RS_NET_CONN_TUNNEL)
|
||||
{
|
||||
#ifdef LINKMGR_DEBUG
|
||||
std::cerr << "p3LinkMgrIMPL::retryConnectTCP() Peer Connected through a tunnel connection, let's try a normal connection." << std::endl;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef LINKMGR_DEBUG
|
||||
std::cerr << "p3LinkMgrIMPL::retryConnectTCP() Peer Connected no more connection attempts" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} /****** END of LOCKED ******/
|
||||
|
||||
|
@ -1683,8 +1642,6 @@ bool p3LinkMgrIMPL::retryConnectTCP(const std::string &id)
|
|||
|
||||
locked_ConnectAttempt_HistoricalAddresses(&(it->second), histAddrs);
|
||||
|
||||
//locked_ConnectAttempt_AddTunnel(&(it->second));
|
||||
|
||||
/* finish it off */
|
||||
return locked_ConnectAttempt_Complete(&(it->second));
|
||||
}
|
||||
|
@ -2046,31 +2003,6 @@ void p3LinkMgrIMPL::locked_ConnectAttempt_ProxyAddress(peerConnectState *peer,
|
|||
}
|
||||
|
||||
|
||||
void p3LinkMgrIMPL::locked_ConnectAttempt_AddTunnel(peerConnectState *peer)
|
||||
{
|
||||
if (!(peer->state & RS_PEER_S_CONNECTED) && mAllowTunnelConnection)
|
||||
{
|
||||
#ifdef LINKMGR_DEBUG
|
||||
std::cerr << "Adding TUNNEL Connection Attempt";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
peerConnectAddress pca;
|
||||
pca.type = RS_NET_CONN_TUNNEL;
|
||||
pca.ts = time(NULL);
|
||||
pca.period = 0;
|
||||
|
||||
sockaddr_clear(&pca.addr);
|
||||
|
||||
sockaddr_clear(&(pca.proxyaddr));
|
||||
sockaddr_clear(&(pca.srcaddr));
|
||||
pca.bandwidth = 0;
|
||||
|
||||
|
||||
addAddressIfUnique(peer->connAddrs, pca, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool p3LinkMgrIMPL::addAddressIfUnique(std::list<peerConnectAddress> &addrList, peerConnectAddress &pca, bool pushFront)
|
||||
{
|
||||
/* iterate through the list, and make sure it isn't already
|
||||
|
|
|
@ -42,7 +42,6 @@ class DNSResolver ;
|
|||
/* order of attempts ... */
|
||||
const uint32_t RS_NET_CONN_TCP_ALL = 0x000f;
|
||||
const uint32_t RS_NET_CONN_UDP_ALL = 0x00f0;
|
||||
const uint32_t RS_NET_CONN_TUNNEL = 0x0f00;
|
||||
|
||||
const uint32_t RS_NET_CONN_TCP_LOCAL = 0x0001;
|
||||
const uint32_t RS_NET_CONN_TCP_EXTERNAL = 0x0002;
|
||||
|
@ -182,8 +181,6 @@ virtual struct sockaddr_in getLocalAddress() = 0;
|
|||
virtual void getFriendList(std::list<std::string> &ssl_peers) = 0; // ONLY used by p3peers.cc USE p3PeerMgr instead.
|
||||
virtual bool getFriendNetStatus(const std::string &id, peerConnectState &state) = 0; // ONLY used by p3peers.cc
|
||||
|
||||
virtual void setTunnelConnection(bool b) = 0; // ONLY used by p3peermgr.cc & p3peers.cc MOVE => p3PeerMgr
|
||||
virtual bool getTunnelConnection() = 0; // ONLY used by p3peermgr.cc & p3peers.cc MOVE => p3PeerMgr
|
||||
|
||||
/************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
|
||||
virtual int addFriend(const std::string &ssl_id, bool isVisible) = 0;
|
||||
|
@ -250,9 +247,6 @@ virtual void peerConnectRequest(std::string id, struct sockaddr_in raddr,
|
|||
virtual void getFriendList(std::list<std::string> &ssl_peers); // ONLY used by p3peers.cc USE p3PeerMgr instead.
|
||||
virtual bool getFriendNetStatus(const std::string &id, peerConnectState &state); // ONLY used by p3peers.cc
|
||||
|
||||
virtual void setTunnelConnection(bool b); // ONLY used by p3peermgr.cc & p3peers.cc MOVE => p3PeerMgr
|
||||
virtual bool getTunnelConnection(); // ONLY used by p3peermgr.cc & p3peers.cc MOVE => p3PeerMgr
|
||||
|
||||
/************************************************************************************************/
|
||||
/* Extra IMPL Functions (used by p3PeerMgr, p3NetMgr + Setup) */
|
||||
/************************************************************************************************/
|
||||
|
|
|
@ -1381,7 +1381,6 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
|||
/* create a list of current peers */
|
||||
cleanup = false;
|
||||
bool useExtAddrFinder = mNetMgr->getIPServersEnabled();
|
||||
bool allowTunnelConnection = mLinkMgr->getTunnelConnection();
|
||||
|
||||
mPeerMtx.lock(); /****** MUTEX LOCKED *******/
|
||||
|
||||
|
@ -1486,14 +1485,6 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
|||
|
||||
RsConfigKeyValueSet *vitem2 = new RsConfigKeyValueSet ;
|
||||
|
||||
RsTlvKeyValue kv2;
|
||||
kv2.key = "ALLOW_TUNNEL_CONNECTION" ;
|
||||
kv2.value = (allowTunnelConnection)?"TRUE":"FALSE" ;
|
||||
vitem2->tlvkvs.pairs.push_back(kv2) ;
|
||||
|
||||
#ifdef PEER_DEBUG
|
||||
std::cout << "Pushing item for allow_tunnel_connection = " << allowTunnelConnection << std::endl ;
|
||||
#endif
|
||||
saveData.push_back(vitem2);
|
||||
saveCleanupList.push_back(vitem2);
|
||||
|
||||
|
@ -1527,7 +1518,6 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
|
|||
|
||||
// DEFAULTS.
|
||||
bool useExtAddrFinder = true;
|
||||
bool allowTunnelConnection = true;
|
||||
|
||||
if (load.size() == 0) {
|
||||
std::cerr << "p3PeerMgrIMPL::loadList() list is empty, it may be a configuration problem." << std::endl;
|
||||
|
@ -1613,10 +1603,7 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
|
|||
if(kit->key == "USE_EXTR_IP_FINDER") {
|
||||
useExtAddrFinder = (kit->value == "TRUE");
|
||||
std::cerr << "setting use_extr_addr_finder to " << useExtAddrFinder << std::endl ;
|
||||
} else if (kit->key == "ALLOW_TUNNEL_CONNECTION") {
|
||||
allowTunnelConnection = (kit->value == "TRUE");
|
||||
std::cerr << "setting allow_tunnel_connection to " << allowTunnelConnection << std::endl ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete(*it);
|
||||
|
@ -1714,7 +1701,6 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
|
|||
}
|
||||
|
||||
mNetMgr->setIPServersEnabled(useExtAddrFinder);
|
||||
mLinkMgr->setTunnelConnection(allowTunnelConnection);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -237,7 +237,6 @@ class PQInterface: public RateInterface
|
|||
|
||||
const uint32_t PQI_CONNECT_TCP = 0x0001;
|
||||
const uint32_t PQI_CONNECT_UDP = 0x0002;
|
||||
const uint32_t PQI_CONNECT_TUNNEL = 0x0003;
|
||||
const uint32_t PQI_CONNECT_HIDDEN_TCP = 0x0004;
|
||||
|
||||
|
||||
|
|
|
@ -595,15 +595,6 @@ int pqipersongrp::connectPeer(std::string id
|
|||
#ifdef PGRP_DEBUG
|
||||
std::cerr << " pqipersongrp::connectPeer() connecting with UDP: Timeout :" << timeout;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
}
|
||||
else if (type & RS_NET_CONN_TUNNEL)
|
||||
{
|
||||
ptype = PQI_CONNECT_TUNNEL;
|
||||
timeout = period * 2;
|
||||
#ifdef PGRP_DEBUG
|
||||
std::cerr << " pqipersongrp::connectPeer() connecting with Tunnel: Timeout :" << timeout;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
|
@ -631,11 +622,6 @@ bool pqipersongrp::notifyConnect(std::string id, uint32_t ptype, bool success
|
|||
{
|
||||
type = RS_NET_CONN_UDP_ALL;
|
||||
}
|
||||
else if (ptype == PQI_CONNECT_TUNNEL)
|
||||
{
|
||||
type = RS_NET_CONN_TUNNEL;
|
||||
}
|
||||
|
||||
|
||||
if (mLinkMgr)
|
||||
mLinkMgr->connectResult(id, success, type, raddr);
|
||||
|
|
|
@ -41,9 +41,6 @@ const int pqipersongrpzone = 354;
|
|||
#include "pqi/pqissllistener.h"
|
||||
#include "pqi/p3peermgr.h"
|
||||
|
||||
#ifndef PQI_DISABLE_TUNNEL
|
||||
#include "pqi/pqissltunnel.h"
|
||||
#endif
|
||||
|
||||
#ifndef PQI_DISABLE_UDP
|
||||
#include "pqi/pqissludp.h"
|
||||
|
|
|
@ -1,554 +0,0 @@
|
|||
/*
|
||||
* "$Id: pqissl.cc,v 1.28 2007-03-17 19:32:59 rmf24 Exp $"
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2004-2006 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 "pqi/pqissltunnel.h"
|
||||
#include "pqi/pqinetwork.h"
|
||||
#include "pqi/p3linkmgr.h"
|
||||
|
||||
//#include "services/p3tunnel.h"
|
||||
|
||||
#include "util/rsnet.h"
|
||||
#include "util/rsdebug.h"
|
||||
#include "util/rsstring.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
const int pqisslzone = 37714;
|
||||
|
||||
#define TUNNEL_WAITING_NOT 0
|
||||
#define TUNNEL_WAITING_DELAY 1
|
||||
#define TUNNEL_WAITING_SPAM_HANDSHAKE 2
|
||||
#define TUNNEL_WAITING_RETURN_HANDSHAKE 3
|
||||
|
||||
|
||||
#define TUNNEL_PASSIVE 0x00
|
||||
#define TUNNEL_ACTIVE 0x01
|
||||
|
||||
#define TUNNEL_START_CONNECTION_DELAY 1
|
||||
#define TUNNEL_PING_TIMEOUT 6
|
||||
#define TUNNEL_REPEAT_PING_TIME 2
|
||||
#define TUNNEL_TIMEOUT_AFTER_RESET 30
|
||||
|
||||
#define TUNNEL_TRY_OTHER_CONNECTION_INTERVAL 190 //let's try a normal tcp or udp connection every 190 sec
|
||||
|
||||
//const int TUNNEL_LOCAL_FLAG = 0x01;
|
||||
//const int TUNNEL_REMOTE_FLAG = 0x02;
|
||||
//const int TUNNEL_UDP_FLAG = 0x02;
|
||||
//
|
||||
//static const int PQISSL_MAX_READ_ZERO_COUNT = 20;
|
||||
//static const int PQISSL_SSL_CONNECT_TIMEOUT = 30;
|
||||
|
||||
/********** PQI SSL STUFF ******************************************
|
||||
*
|
||||
* A little note on the notifyEvent(FAILED)....
|
||||
*
|
||||
* this is called from
|
||||
* (1) reset if needed!
|
||||
* (2) Determine_Remote_Address (when all options have failed).
|
||||
*
|
||||
* reset() is only called when a TCP/SSL connection has been
|
||||
* established, and there is an error. If there is a failed TCP
|
||||
* connection, then an alternative address can be attempted.
|
||||
*
|
||||
* reset() is called from
|
||||
* (1) destruction.
|
||||
* (2) disconnect()
|
||||
* (3) bad waiting state.
|
||||
*
|
||||
* // TCP/or SSL connection already established....
|
||||
* (5) pqissltunnel::SSL_Connection_Complete() <- okay -> cos we made a TCP connection already.
|
||||
* (6) pqissltunnel::accept() <- okay cos something went wrong.
|
||||
* (7) moretoread()/cansend() <- okay cos
|
||||
*
|
||||
*/
|
||||
|
||||
pqissltunnel::pqissltunnel(PQInterface *parent, p3LinkMgr *cm, p3tunnel *p3t)
|
||||
:NetBinInterface(parent, parent->PeerId()), mLinkMgr(cm)
|
||||
{
|
||||
active = false;
|
||||
waiting = TUNNEL_WAITING_NOT;
|
||||
|
||||
rslog(RSL_ALERT, pqisslzone, "pqissltunnel for PeerId: " + PeerId());
|
||||
|
||||
// if (!(AuthSSL::getAuthSSL()->isAuthenticated(PeerId()))) {
|
||||
// rslog(RSL_ALERT, pqisslzone,
|
||||
// "pqissltunnel::Warning Certificate Not Approved!");
|
||||
// rslog(RSL_ALERT, pqisslzone,
|
||||
// "\t pqissltunnel will not initialise....");
|
||||
// }
|
||||
mP3tunnel = p3t;
|
||||
current_data_offset = 0;
|
||||
curent_data_packet.length = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
pqissltunnel::~pqissltunnel() {
|
||||
rslog(RSL_ALERT, pqisslzone,
|
||||
"pqissltunnel::~pqissltunnel -> destroying pqissl");
|
||||
//stoplistening();
|
||||
reset();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/********** Implementation of NetInterface *************************/
|
||||
|
||||
int pqissltunnel::connect(struct sockaddr_in /*raddr*/) {
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::connect() called : " << PeerId() << std::endl;
|
||||
#endif
|
||||
last_normal_connection_attempt_time = time(NULL);
|
||||
mConnectTS = time(NULL);
|
||||
resetTime = time(NULL) - TUNNEL_TIMEOUT_AFTER_RESET;
|
||||
waiting = TUNNEL_WAITING_DELAY;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// tells pqilistener to listen for us.
|
||||
int pqissltunnel::listen()
|
||||
{
|
||||
//no use
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pqissltunnel::stoplistening()
|
||||
{
|
||||
//no use
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pqissltunnel::disconnect()
|
||||
{
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::disconnect() called : " << PeerId() << std::endl;
|
||||
#endif
|
||||
return reset();
|
||||
}
|
||||
|
||||
/* BinInterface version of reset() for pqistreamer */
|
||||
int pqissltunnel::close()
|
||||
{
|
||||
return reset();
|
||||
}
|
||||
|
||||
// put back on the listening queue.
|
||||
int pqissltunnel::reset()
|
||||
{
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::reset() called : " << PeerId() << std::endl;
|
||||
#endif
|
||||
|
||||
if (active)
|
||||
{
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::reset() Reset Required because tunnel was activated !" << std::endl;
|
||||
std::cerr << "pqissltunnel::reset() Will Attempt notifyEvent(FAILED)" << std::endl;
|
||||
#endif
|
||||
waiting = TUNNEL_WAITING_NOT;
|
||||
active = false;
|
||||
resetTime = time(NULL);
|
||||
// clean up the streamer
|
||||
if (parent()) {
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::reset() notifyEvent(FAILED)" << std::endl;
|
||||
#endif
|
||||
parent() -> notifyEvent(this, NET_CONNECT_FAILED);
|
||||
}
|
||||
} else {
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::reset() Reset not required because tunnel was not activated !" << std::endl;
|
||||
#endif
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pqissltunnel::getConnectAddress(struct sockaddr_in &raddr) {
|
||||
sockaddr_clear(&raddr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool pqissltunnel::connect_parameter(uint32_t type, uint32_t value)
|
||||
{
|
||||
{
|
||||
std::string out = "pqissltunnel::connect_parameter() (not used) Peer: " + PeerId();
|
||||
rs_sprintf_append(out, " type: %lu value: %lu", type, value);
|
||||
rslog(RSL_DEBUG_ALL, pqisslzone, out);
|
||||
}
|
||||
|
||||
if (type == NET_PARAM_CONNECT_DELAY)
|
||||
{
|
||||
std::string out = "pqissltunnel::connect_parameter() (not used) Peer: " + PeerId();
|
||||
rs_sprintf_append(out, " DELAY: %lu", value);
|
||||
rslog(RSL_WARNING, pqisslzone, out);
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (type == NET_PARAM_CONNECT_TIMEOUT)
|
||||
{
|
||||
std::string out = "pqissltunnel::connect_parameter() (not used) Peer: " + PeerId();
|
||||
rs_sprintf_append(out, " TIMEOUT: %lu", value);
|
||||
rslog(RSL_WARNING, pqisslzone, out);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/********** End of Implementation of NetInterface ******************/
|
||||
/********** Implementation of BinInterface **************************
|
||||
* Only status() + tick() are here ... as they are really related
|
||||
* to the NetInterface, and not the BinInterface,
|
||||
*
|
||||
*/
|
||||
|
||||
/* returns ...
|
||||
* -1 if inactive.
|
||||
* 0 if connecting.
|
||||
* 1 if connected.
|
||||
*/
|
||||
|
||||
int pqissltunnel::status()
|
||||
{
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::status() called." << std::endl;
|
||||
#endif
|
||||
|
||||
if (active) {
|
||||
std::cerr << " active: " << std::endl;
|
||||
// print out connection.
|
||||
std::cerr << "dest : " << PeerId();
|
||||
std::cerr << "relay : " << relayPeerId;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
else {
|
||||
std::cerr << " Waiting for connection!" << std::endl;
|
||||
}
|
||||
|
||||
if (active) {
|
||||
return 1;
|
||||
} else if (waiting > 0) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int pqissltunnel::tick()
|
||||
{
|
||||
if (active && ((time(NULL) - last_normal_connection_attempt_time) > TUNNEL_TRY_OTHER_CONNECTION_INTERVAL)) {
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::tick() attempt to connect through a normal tcp or udp connection." << std::endl;
|
||||
#endif
|
||||
last_normal_connection_attempt_time = time(NULL);
|
||||
mLinkMgr->retryConnect(parent()->PeerId());
|
||||
}
|
||||
|
||||
if (active && ((time(NULL) - last_ping_send_time) > TUNNEL_REPEAT_PING_TIME)) {
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::tick() sending a ping." << std::endl;
|
||||
#endif
|
||||
last_ping_send_time = time(NULL);;
|
||||
mP3tunnel->pingTunnelConnection(relayPeerId, parent()->PeerId());
|
||||
}
|
||||
|
||||
if (active && ((time(NULL) - last_packet_time) > TUNNEL_PING_TIMEOUT)) {
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::tick() no packet received since PING_RECEIVE_TIME_OUT. Connection is broken." << std::endl;
|
||||
#endif
|
||||
reset();
|
||||
}
|
||||
// continue existing connection attempt.
|
||||
if (!active)
|
||||
{
|
||||
// if we are waiting.. continue the connection (only)
|
||||
if (waiting > 0)
|
||||
{
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
//std::cerr << "pqissltunnel::tick() Continuing Connection Attempt!" << std::endl;
|
||||
#endif
|
||||
ConnectAttempt();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/********** End of Implementation of BinInterface ******************/
|
||||
/********** Internals of Tunnel Connection ****************************/
|
||||
int pqissltunnel::ConnectAttempt()
|
||||
{
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
//std::cerr << "pqissltunnel::ConnectAttempt() called." << std::endl;
|
||||
#endif
|
||||
switch(waiting)
|
||||
{
|
||||
case TUNNEL_WAITING_NOT:
|
||||
active = true; /* we're starting this one */
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::ConnectAttempt() STATE = Not Waiting." << std::endl;
|
||||
#endif
|
||||
|
||||
case TUNNEL_WAITING_DELAY:
|
||||
if ((time(NULL) - mConnectTS) > TUNNEL_START_CONNECTION_DELAY) {
|
||||
waiting = TUNNEL_WAITING_SPAM_HANDSHAKE;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case TUNNEL_WAITING_SPAM_HANDSHAKE:
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::ConnectAttempt() STATE = Waiting for spamming handshake." << std::endl;
|
||||
#endif
|
||||
|
||||
spam_handshake();
|
||||
waiting = TUNNEL_WAITING_RETURN_HANDSHAKE;
|
||||
break;
|
||||
|
||||
case TUNNEL_WAITING_RETURN_HANDSHAKE:
|
||||
if ((time(NULL) - mConnectTS) < TUNNEL_PING_TIMEOUT) {
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
//std::cerr << "pqissltunnel::ConnectAttempt() STATE = Waiting for handshake reply." << std::endl;
|
||||
#endif
|
||||
} else {
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::ConnectAttempt() no handshake reply during imparing time. Connection failed." << std::endl;
|
||||
#endif
|
||||
waiting = TUNNEL_WAITING_NOT;
|
||||
active = false;
|
||||
// clean up the streamer
|
||||
if (parent()) {
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::reset() Reset not required because tunnel was not activated !" << std::endl;
|
||||
#endif
|
||||
parent() -> notifyEvent(this, NET_CONNECT_FAILED);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
std::cerr << "pqissltunnel::ConnectAttempt() STATE = Unknown - Reset" << std::endl;
|
||||
|
||||
reset();
|
||||
break;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void pqissltunnel::spam_handshake()
|
||||
{
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::spam_handshake() starting to spam handshake tunnel packet." << std::endl;
|
||||
#endif
|
||||
std::list<std::string> peers;
|
||||
mLinkMgr->getOnlineList(peers);
|
||||
std::list<std::string>::iterator it = peers.begin();
|
||||
while (it != peers.end()) {
|
||||
//send a handshake to the destination through the relay
|
||||
if (*it != parent()->PeerId()) {
|
||||
mP3tunnel->initiateHandshake(*it, parent()->PeerId());
|
||||
}
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
void pqissltunnel::addIncomingPacket(void* encoded_data, int encoded_data_length) {
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::addIncomingPacket() called." << std::endl;
|
||||
#endif
|
||||
last_packet_time = time(NULL);
|
||||
|
||||
data_with_length data_w_l;
|
||||
data_w_l.data = (void*)malloc(encoded_data_length) ;
|
||||
memcpy(data_w_l.data, encoded_data, encoded_data_length);
|
||||
data_w_l.length = encoded_data_length;
|
||||
data_packet_queue.push_front(data_w_l);
|
||||
}
|
||||
|
||||
void pqissltunnel::IncommingPingPacket() {
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::IncommingPingPacket() called" << std::endl;
|
||||
#endif
|
||||
|
||||
last_packet_time = time(NULL);
|
||||
}
|
||||
|
||||
void pqissltunnel::IncommingHanshakePacket(std::string incRelayPeerId) {
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::IncommingHanshakePacket() called with incRelayPeerId : " << incRelayPeerId << std::endl;
|
||||
#endif
|
||||
|
||||
if ((time(NULL) - resetTime) <= TUNNEL_TIMEOUT_AFTER_RESET) {
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::IncommingHanshakePacket() a reset occured, don't activate the connection." << std::endl;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
last_packet_time = time(NULL);
|
||||
|
||||
std::string message = "pqissltunnel::IncommingHanshakePacket() mConnMgr->isOnline(parent()->PeerId() : ";
|
||||
if (mLinkMgr->isOnline(parent()->PeerId())) {
|
||||
message += "true";
|
||||
} else {
|
||||
message += "false";
|
||||
}
|
||||
rslog(RSL_DEBUG_BASIC, pqisslzone, message);
|
||||
|
||||
if (active || mLinkMgr->isOnline(parent()->PeerId())) {
|
||||
//connection is already active, or peer is already online don't do nothing
|
||||
return;
|
||||
}
|
||||
//TODO : check if cert is in order before accepting
|
||||
|
||||
//activate connection
|
||||
waiting = TUNNEL_WAITING_NOT;
|
||||
active = true;
|
||||
relayPeerId = incRelayPeerId;
|
||||
|
||||
if (parent())
|
||||
{
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::IncommingHanshakePacket() Notify the pqiperson.... (Both Connect/Receive)" << parent()->PeerId() <<std::endl;
|
||||
#endif
|
||||
rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissltunnel::IncommingHanshakePacket() Notify the pqiperson.... (Both Connect/Receive)");
|
||||
parent() -> notifyEvent(this, NET_CONNECT_SUCCESS);
|
||||
}
|
||||
}
|
||||
/********** Implementation of BinInterface **************************
|
||||
* All the rest of the BinInterface.
|
||||
*
|
||||
*/
|
||||
|
||||
int pqissltunnel::senddata(void *data, int len)
|
||||
{
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::senddata() called" << std::endl ;
|
||||
#endif
|
||||
if (!active) {
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::senddata() connection is not active" << std::endl ;
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
int outlen = 0;
|
||||
void * out;
|
||||
if (!AuthSSL::getAuthSSL()->encrypt(out, outlen, data, len, parent()->PeerId())) {
|
||||
std::cerr << "pqissltunnel::senddata() problem while crypting packet, ignoring it." << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::senddata() sending item via p3tunnel" << std::endl ;
|
||||
#endif
|
||||
mP3tunnel->sendTunnelData(parent()->PeerId(), relayPeerId, out, outlen);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int pqissltunnel::readdata(void *data, int len)
|
||||
{
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cout << "pqissltunnel::readdata() called" << std::endl ;
|
||||
#endif
|
||||
//let's see if we got a new packet to read
|
||||
if (current_data_offset >= curent_data_packet.length) {
|
||||
//current packet has finished reading, let's pop out a new packet if available
|
||||
if (data_packet_queue.size() ==0) {
|
||||
//no more to read
|
||||
return -1;
|
||||
} else {
|
||||
//let's read a new packet
|
||||
current_data_offset = 0;
|
||||
//decrypt one packet from the queue and put it into the current data packet.
|
||||
if (!AuthSSL::getAuthSSL()->decrypt(curent_data_packet.data, curent_data_packet.length, data_packet_queue.back().data, data_packet_queue.back().length)) {
|
||||
std::cerr << "pqissltunnel::readdata() problem while decrypting packet, ignoring it." << std::endl;
|
||||
curent_data_packet.length = 0;
|
||||
return -1;
|
||||
}
|
||||
data_packet_queue.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
if (current_data_offset < curent_data_packet.length) {
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cout << "pqissltunnel::readdata() reading..." << std::endl ;
|
||||
std::cout << "pqissltunnel::readdata() len : " << len << std::endl ;
|
||||
std::cout << "pqissltunnel::readdata() current_data_offset : " << current_data_offset << std::endl ;
|
||||
std::cout << "pqissltunnel::readdata() curent_data_packet.length : " << curent_data_packet.length << std::endl ;
|
||||
std::cerr << "pqissltunnel::readdata() getRsItemSize(curent_data_packet.data) : " << getRsItemSize(curent_data_packet.data) << std::endl;
|
||||
#endif
|
||||
|
||||
//read from packet
|
||||
memcpy(data, (void*)((unsigned long int)curent_data_packet.data+(unsigned long int)current_data_offset), len);
|
||||
current_data_offset += len;
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
// dummy function currently.
|
||||
int pqissltunnel::netstatus()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pqissltunnel::isactive()
|
||||
{
|
||||
return active;
|
||||
}
|
||||
|
||||
bool pqissltunnel::moretoread()
|
||||
{
|
||||
//let's see if we got an old packet or a new packet to read
|
||||
if (current_data_offset >= curent_data_packet.length && data_packet_queue.size() ==0) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool pqissltunnel::cansend()
|
||||
{
|
||||
if (!mLinkMgr->isOnline(relayPeerId)) {
|
||||
reset();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string pqissltunnel::gethash()
|
||||
{
|
||||
std::string dummyhash;
|
||||
return dummyhash;
|
||||
}
|
||||
|
||||
/********** End of Implementation of BinInterface ******************/
|
|
@ -1,146 +0,0 @@
|
|||
/*
|
||||
* "$Id: pqissl.h,v 1.18 2007-03-11 14:54:22 rmf24 Exp $"
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2004-2006 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".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef MRK_PQI_SSL_TUNNEL_HEADER
|
||||
#define MRK_PQI_SSL_TUNNEL_HEADER
|
||||
|
||||
#include "util/rswin.h"
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
// operating system specific network header.
|
||||
//#include "pqi/pqinetwork.h"
|
||||
|
||||
#include "pqi/pqi_base.h"
|
||||
|
||||
#include "services/p3tunnel.h"
|
||||
|
||||
#include "pqi/authssl.h"
|
||||
|
||||
/***************************** pqi Net SSL Interface *********************************
|
||||
* This provides the base SSL interface class,
|
||||
* and handles most of the required functionality.
|
||||
*
|
||||
* there are a series of small fn's that can be overloaded
|
||||
* to provide alternative behaviour....
|
||||
*
|
||||
* Classes expected to inherit from this are:
|
||||
*
|
||||
* pqissllistener -> pqissllistener (tcp only)
|
||||
* -> pqixpgplistener (tcp only)
|
||||
*
|
||||
* pqissl -> pqissltcp
|
||||
* -> pqissludp
|
||||
* -> pqixpgptcp
|
||||
* -> pqixpgpudp
|
||||
*
|
||||
*/
|
||||
|
||||
class pqissl;
|
||||
class cert;
|
||||
|
||||
class pqissltunnellistener;
|
||||
|
||||
class p3LinkMgr;
|
||||
|
||||
struct data_with_length {
|
||||
int length;
|
||||
void *data;
|
||||
};
|
||||
|
||||
class pqissltunnel: public NetBinInterface
|
||||
{
|
||||
public:
|
||||
pqissltunnel(PQInterface *parent, p3LinkMgr *cm, p3tunnel *p3t);
|
||||
virtual ~pqissltunnel();
|
||||
|
||||
// NetInterface
|
||||
|
||||
//the addr is not used for the tunnel
|
||||
virtual int connect(struct sockaddr_in raddr);
|
||||
virtual int listen();
|
||||
virtual int stoplistening();
|
||||
virtual int reset();
|
||||
virtual int disconnect();
|
||||
virtual int getConnectAddress(struct sockaddr_in &raddr);
|
||||
|
||||
virtual bool connect_parameter(uint32_t type, uint32_t value);
|
||||
|
||||
// BinInterface
|
||||
virtual int tick();
|
||||
virtual int status();
|
||||
|
||||
virtual int senddata(void*, int);
|
||||
virtual int readdata(void*, int);
|
||||
virtual int netstatus();
|
||||
virtual int isactive();
|
||||
virtual bool moretoread();
|
||||
virtual bool cansend();
|
||||
|
||||
virtual int close(); /* BinInterface version of reset() */
|
||||
virtual std::string gethash(); /* not used here */
|
||||
virtual bool bandwidthLimited() { return true ; } // replace by !sameLAN to avoid bandwidth limiting on lAN
|
||||
|
||||
//called by the p3tunnel service to add incoming packets that will be read by the read data function.
|
||||
void addIncomingPacket(void* encoded_data, int data_length);
|
||||
void IncommingPingPacket();
|
||||
void IncommingHanshakePacket(std::string incRelayPeerId);
|
||||
|
||||
private:
|
||||
//if no packet (last_time_packet_time) is received since PING_RECEIVE_TIME_OUT, let's assume the connection is broken
|
||||
int last_normal_connection_attempt_time;
|
||||
|
||||
//if no packet (last_time_packet_time) is received since PING_RECEIVE_TIME_OUT, let's assume the connection is broken
|
||||
int last_packet_time;
|
||||
|
||||
//send a ping on a regular basis
|
||||
int last_ping_send_time;
|
||||
|
||||
int ConnectAttempt();
|
||||
void spam_handshake();
|
||||
int waiting;
|
||||
bool active;
|
||||
time_t resetTime;
|
||||
pqissltunnellistener *pqil;
|
||||
|
||||
/* Need Certificate specific functions here! */
|
||||
time_t mConnectTS;
|
||||
|
||||
p3LinkMgr *mLinkMgr;
|
||||
|
||||
p3tunnel *mP3tunnel;
|
||||
|
||||
std::list<data_with_length> data_packet_queue;
|
||||
data_with_length curent_data_packet;
|
||||
int current_data_offset;
|
||||
|
||||
//tunneling details
|
||||
std::string relayPeerId;
|
||||
|
||||
};
|
||||
|
||||
#endif // MRK_PQI_SSL_HEADER
|
Loading…
Add table
Add a link
Reference in a new issue