2007-11-14 22:18:48 -05:00
|
|
|
/*
|
|
|
|
* "$Id: pqissludp.cc,v 1.16 2007-02-18 21:46:49 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/pqissludp.h"
|
|
|
|
#include "pqi/pqinetwork.h"
|
|
|
|
|
|
|
|
#include "tcponudp/tou.h"
|
|
|
|
#include "tcponudp/bio_tou.h"
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <openssl/err.h>
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
2008-07-10 12:29:18 -04:00
|
|
|
#include "util/rsdebug.h"
|
2008-02-26 21:32:20 -05:00
|
|
|
#include "util/rsnet.h"
|
|
|
|
|
2011-07-09 14:39:34 -04:00
|
|
|
#include "pqi/p3linkmgr.h"
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
const int pqissludpzone = 3144;
|
|
|
|
|
|
|
|
/* a final timeout, to ensure this never blocks completely
|
|
|
|
* 300 secs to complete udp/tcp/ssl connection.
|
|
|
|
* This is long as the udp connect can take some time.
|
|
|
|
*/
|
2008-02-26 21:32:20 -05:00
|
|
|
|
|
|
|
static const uint32_t PQI_SSLUDP_DEF_CONN_PERIOD = 300; /* 5 minutes? */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/********** PQI SSL UDP STUFF **************************************/
|
|
|
|
|
2011-07-09 14:39:34 -04:00
|
|
|
pqissludp::pqissludp(PQInterface *parent, p3LinkMgr *lm)
|
|
|
|
:pqissl(NULL, parent, lm), tou_bio(NULL),
|
2008-02-26 21:32:20 -05:00
|
|
|
listen_checktime(0), mConnectPeriod(PQI_SSLUDP_DEF_CONN_PERIOD)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2008-02-26 21:32:20 -05:00
|
|
|
sockaddr_clear(&remote_addr);
|
2007-11-14 22:18:48 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pqissludp::~pqissludp()
|
|
|
|
{
|
2008-07-10 12:29:18 -04:00
|
|
|
rslog(RSL_ALERT, pqissludpzone,
|
2008-01-25 01:36:40 -05:00
|
|
|
"pqissludp::~pqissludp -> destroying pqissludp");
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* must call reset from here, so that the
|
|
|
|
* virtual functions will still work.
|
|
|
|
* -> as they stop working in base class destructor.
|
|
|
|
*
|
|
|
|
* This means that reset() will be called twice, but this should
|
|
|
|
* be harmless.
|
|
|
|
*/
|
|
|
|
stoplistening(); /* remove from p3proxy listenqueue */
|
|
|
|
reset();
|
|
|
|
|
|
|
|
if (tou_bio) // this should be in the reset?
|
|
|
|
{
|
|
|
|
BIO_free(tou_bio);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int pqissludp::reset()
|
|
|
|
{
|
|
|
|
/* reset for next time.*/
|
2011-07-13 18:23:40 -04:00
|
|
|
mConnectFlags = 0;
|
|
|
|
mConnectPeriod = PQI_SSLUDP_DEF_CONN_PERIOD;
|
2007-11-14 22:18:48 -05:00
|
|
|
return pqissl::reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* <===================== UDP Difference *******************/
|
|
|
|
// The Proxy Version takes a few more step
|
|
|
|
//
|
|
|
|
// connectInterface is sent via message from the proxy.
|
|
|
|
// and is set here.
|
|
|
|
/* <===================== UDP Difference *******************/
|
|
|
|
|
2008-01-25 01:36:40 -05:00
|
|
|
int pqissludp::attach()
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2011-06-29 14:02:44 -04:00
|
|
|
// IN THE IMPROVED TOU LIBRARY, we need to be careful with the tou_socket PARAMETERS.
|
|
|
|
// For now, this should do!
|
2011-07-14 10:56:33 -04:00
|
|
|
sockfd = -1;
|
|
|
|
|
|
|
|
if (mConnectFlags & RS_CB_FLAG_MODE_UDP_DIRECT)
|
|
|
|
{
|
2011-07-18 14:28:20 -04:00
|
|
|
std::cerr << "pqissludp::attach() Opening DIRECT Socket";
|
|
|
|
std::cerr << std::endl;
|
2011-07-14 10:56:33 -04:00
|
|
|
sockfd = tou_socket(RSUDP_TOU_RECVER_DIRECT_IDX,TOU_RECEIVER_TYPE_UDPPEER,0);
|
|
|
|
}
|
|
|
|
else if (mConnectFlags & RS_CB_FLAG_MODE_UDP_PROXY)
|
|
|
|
{
|
2011-07-18 14:28:20 -04:00
|
|
|
std::cerr << "pqissludp::attach() Opening PROXY Socket";
|
|
|
|
std::cerr << std::endl;
|
2011-07-14 10:56:33 -04:00
|
|
|
sockfd = tou_socket(RSUDP_TOU_RECVER_PROXY_IDX,TOU_RECEIVER_TYPE_UDPPEER,0);
|
|
|
|
}
|
|
|
|
else if (mConnectFlags & RS_CB_FLAG_MODE_UDP_RELAY)
|
|
|
|
{
|
2011-07-18 14:28:20 -04:00
|
|
|
std::cerr << "pqissludp::attach() Opening RELAY Socket";
|
|
|
|
std::cerr << std::endl;
|
2011-07-14 10:56:33 -04:00
|
|
|
sockfd = tou_socket(RSUDP_TOU_RECVER_RELAY_IDX,TOU_RECEIVER_TYPE_UDPRELAY,0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "pqissludp::attach() ERROR unknown Connect Mode" << std::endl;
|
2011-07-18 14:28:20 -04:00
|
|
|
std::cerr << "pqissludp::attach() mConnectFlags: " << std::hex << mConnectFlags << std::dec;
|
|
|
|
std::cerr << std::endl;
|
2011-07-14 10:56:33 -04:00
|
|
|
sockfd = -1;
|
|
|
|
}
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
if (0 > sockfd)
|
|
|
|
{
|
2008-07-10 12:29:18 -04:00
|
|
|
rslog(RSL_WARNING, pqissludpzone,
|
2007-11-14 22:18:48 -05:00
|
|
|
"pqissludp::attach() failed to create a socket");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// setup remote address
|
2008-07-10 12:29:18 -04:00
|
|
|
rslog(RSL_WARNING, pqissludpzone,
|
2008-01-25 01:36:40 -05:00
|
|
|
"pqissludp::attach() Opened Local Udp Socket");
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-25 01:36:40 -05:00
|
|
|
// The Address determination is done centrally
|
2007-11-14 22:18:48 -05:00
|
|
|
int pqissludp::Initiate_Connection()
|
|
|
|
{
|
|
|
|
int err;
|
2008-02-26 21:32:20 -05:00
|
|
|
|
|
|
|
attach(); /* open socket */
|
2007-11-14 22:18:48 -05:00
|
|
|
remote_addr.sin_family = AF_INET;
|
|
|
|
|
2008-07-10 12:29:18 -04:00
|
|
|
rslog(RSL_DEBUG_BASIC, pqissludpzone,
|
2007-11-14 22:18:48 -05:00
|
|
|
"pqissludp::Initiate_Connection() Attempting Outgoing Connection....");
|
|
|
|
|
2008-02-26 21:32:20 -05:00
|
|
|
/* decide if we're active or passive */
|
2011-07-14 10:56:33 -04:00
|
|
|
if (mConnectFlags & RS_CB_FLAG_ORDER_ACTIVE)
|
2008-02-26 21:32:20 -05:00
|
|
|
{
|
|
|
|
sslmode = PQISSL_ACTIVE;
|
|
|
|
}
|
2011-07-14 10:56:33 -04:00
|
|
|
else if (mConnectFlags & RS_CB_FLAG_ORDER_PASSIVE)
|
2008-02-26 21:32:20 -05:00
|
|
|
{
|
|
|
|
sslmode = PQISSL_PASSIVE;
|
|
|
|
}
|
2011-07-13 18:23:40 -04:00
|
|
|
else // likely UNSPEC - use old method to decide.
|
|
|
|
{
|
|
|
|
if (PeerId() < mLinkMgr->getOwnId())
|
|
|
|
{
|
|
|
|
sslmode = PQISSL_ACTIVE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sslmode = PQISSL_PASSIVE;
|
|
|
|
}
|
|
|
|
}
|
2008-02-26 21:32:20 -05:00
|
|
|
|
|
|
|
if (waiting != WAITING_DELAY)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2008-07-10 12:29:18 -04:00
|
|
|
rslog(RSL_WARNING, pqissludpzone,
|
2007-11-14 22:18:48 -05:00
|
|
|
"pqissludp::Initiate_Connection() Already Attempt in Progress!");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-07-10 12:29:18 -04:00
|
|
|
if (sockfd < 0)
|
|
|
|
{
|
|
|
|
rslog(RSL_ALERT, pqissludpzone,
|
|
|
|
"pqissludp::Initiate_Connection() Socket Creation Failed!");
|
|
|
|
waiting = WAITING_FAIL_INTERFACE;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rslog(RSL_DEBUG_BASIC, pqissludpzone,
|
2007-11-14 22:18:48 -05:00
|
|
|
"pqissludp::Initiate_Connection() Opening Socket");
|
|
|
|
|
|
|
|
{
|
|
|
|
std::ostringstream out;
|
|
|
|
out << "pqissludp::Initiate_Connection() ";
|
2008-07-10 12:29:18 -04:00
|
|
|
out << "Connecting To: " << PeerId();
|
2010-07-10 16:34:03 -04:00
|
|
|
out << " via: " << rs_inet_ntoa(remote_addr.sin_addr) << ":";
|
2008-07-10 12:29:18 -04:00
|
|
|
out << ntohs(remote_addr.sin_port) << " ";
|
2008-02-26 21:32:20 -05:00
|
|
|
if (sslmode)
|
|
|
|
{
|
2008-07-10 12:29:18 -04:00
|
|
|
out << "ACTIVE Connect (SSL_Connect)";
|
2008-02-26 21:32:20 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-07-10 12:29:18 -04:00
|
|
|
out << "PASSIVE Connect (SSL_Accept)";
|
2008-02-26 21:32:20 -05:00
|
|
|
}
|
2008-07-10 12:29:18 -04:00
|
|
|
rslog(RSL_WARNING, pqissludpzone, out.str());
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (remote_addr.sin_addr.s_addr == 0)
|
|
|
|
{
|
|
|
|
std::ostringstream out;
|
|
|
|
out << "pqissludp::Initiate_Connection() ";
|
|
|
|
out << "Invalid (0.0.0.0) Remote Address,";
|
|
|
|
out << " Aborting Connect.";
|
|
|
|
out << std::endl;
|
2008-07-10 12:29:18 -04:00
|
|
|
rslog(RSL_WARNING, pqissludpzone, out.str());
|
2007-11-14 22:18:48 -05:00
|
|
|
waiting = WAITING_FAIL_INTERFACE;
|
|
|
|
|
|
|
|
reset();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-03-26 11:35:09 -04:00
|
|
|
mTimeoutTS = time(NULL) + mConnectTimeout;
|
2008-07-10 12:29:18 -04:00
|
|
|
//std::cerr << "Setting Connect Timeout " << mConnectTimeout << " Seconds into Future " << std::endl;
|
|
|
|
//std::cerr << " Connect Period is:" << mConnectPeriod << std::endl;
|
2008-03-26 11:35:09 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* <===================== UDP Difference *******************/
|
2011-07-14 10:56:33 -04:00
|
|
|
|
|
|
|
if (mConnectFlags & RS_CB_FLAG_MODE_UDP_DIRECT)
|
|
|
|
{
|
|
|
|
err = tou_connect(sockfd, (struct sockaddr *) &remote_addr, sizeof(remote_addr), mConnectPeriod);
|
|
|
|
}
|
|
|
|
else if (mConnectFlags & RS_CB_FLAG_MODE_UDP_PROXY)
|
|
|
|
{
|
|
|
|
err = tou_connect(sockfd, (struct sockaddr *) &remote_addr, sizeof(remote_addr), mConnectPeriod);
|
|
|
|
}
|
|
|
|
else if (mConnectFlags & RS_CB_FLAG_MODE_UDP_RELAY)
|
|
|
|
{
|
2012-01-08 07:22:35 -05:00
|
|
|
std::cerr << "Calling tou_connect_via_relay(";
|
|
|
|
std::cerr << mConnectSrcAddr << ",";
|
|
|
|
std::cerr << mConnectProxyAddr << ",";
|
|
|
|
std::cerr << remote_addr << ")" << std::endl;
|
|
|
|
|
2011-07-14 10:56:33 -04:00
|
|
|
tou_connect_via_relay(sockfd, &(mConnectSrcAddr), &(mConnectProxyAddr), &(remote_addr));
|
2012-01-10 14:40:35 -05:00
|
|
|
|
|
|
|
/*** It seems that the UDP Layer sees x 1.2 the traffic of the SSL layer.
|
|
|
|
* We need to compensate somewhere... we drop the maximum traffic to 75% of limit
|
|
|
|
* to allow for extra lost packets etc.
|
|
|
|
* NB: If we have a lossy UDP transmission - re-transmission could cause excessive data to
|
|
|
|
* exceed the limit... This is difficult to account for without hacking the TcpOnUdp layer.
|
|
|
|
* If it is noticed as a problem - we'll deal with it then
|
|
|
|
*/
|
|
|
|
#define UDP_RELAY_TRANSPORT_OVERHEAD_FACTOR (0.7)
|
|
|
|
|
|
|
|
parent()->setRateCap( UDP_RELAY_TRANSPORT_OVERHEAD_FACTOR * mConnectBandwidth / 1000.0,
|
|
|
|
UDP_RELAY_TRANSPORT_OVERHEAD_FACTOR * mConnectBandwidth / 1000.0); // Set RateCap.
|
2011-07-14 10:56:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (0 != err)
|
2007-11-14 22:18:48 -05:00
|
|
|
/* <===================== UDP Difference *******************/
|
|
|
|
{
|
|
|
|
int tou_err = tou_errno(sockfd);
|
|
|
|
|
|
|
|
std::ostringstream out;
|
|
|
|
out << "pqissludp::Initiate_Connection()";
|
|
|
|
|
|
|
|
if ((tou_err == EINPROGRESS) || (tou_err == EAGAIN))
|
|
|
|
{
|
|
|
|
// set state to waiting.....
|
|
|
|
waiting = WAITING_SOCK_CONNECT;
|
|
|
|
|
|
|
|
out << " EINPROGRESS Waiting for Socket Connection";
|
2008-07-10 12:29:18 -04:00
|
|
|
rslog(RSL_WARNING, pqissludpzone, out.str());
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if ((tou_err == ENETUNREACH) || (tou_err == ETIMEDOUT))
|
|
|
|
{
|
2008-07-10 12:29:18 -04:00
|
|
|
out << "ENETUNREACHABLE: cert: " << PeerId();
|
2007-11-14 22:18:48 -05:00
|
|
|
out << std::endl;
|
|
|
|
|
|
|
|
// Then send unreachable message.
|
|
|
|
waiting = WAITING_FAIL_INTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
out << "Error: Connection Failed: " << tou_err;
|
|
|
|
out << " - " << socket_errorType(tou_err) << std::endl;
|
|
|
|
|
2008-07-10 12:29:18 -04:00
|
|
|
rslog(RSL_WARNING, pqissludpzone, out.str());
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
reset();
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-07-10 12:29:18 -04:00
|
|
|
rslog(RSL_DEBUG_BASIC, pqissludpzone,
|
2007-11-14 22:18:48 -05:00
|
|
|
"pqissludp::Init_Connection() connect returned 0");
|
|
|
|
}
|
|
|
|
|
|
|
|
waiting = WAITING_SOCK_CONNECT;
|
|
|
|
|
2008-07-10 12:29:18 -04:00
|
|
|
rslog(RSL_DEBUG_BASIC, pqissludpzone,
|
2007-11-14 22:18:48 -05:00
|
|
|
"pqissludp::Initiate_Connection() Waiting for Socket Connect");
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/********* VERY DIFFERENT **********/
|
|
|
|
int pqissludp::Basic_Connection_Complete()
|
|
|
|
{
|
2008-07-10 12:29:18 -04:00
|
|
|
rslog(RSL_DEBUG_BASIC, pqissludpzone,
|
2007-11-14 22:18:48 -05:00
|
|
|
"pqissludp::Basic_Connection_Complete()...");
|
|
|
|
|
|
|
|
|
2008-03-26 11:35:09 -04:00
|
|
|
if (time(NULL) > mTimeoutTS)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2008-07-10 12:29:18 -04:00
|
|
|
std::ostringstream out;
|
|
|
|
out << "pqissludp::Basic_Connection_Complete() Connection Timed Out. ";
|
2010-06-25 17:44:24 -04:00
|
|
|
out << "Peer: " << PeerId() << " Period: ";
|
2008-07-10 12:29:18 -04:00
|
|
|
out << mConnectTimeout;
|
|
|
|
|
|
|
|
rslog(RSL_WARNING, pqissludpzone, out.str());
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* as sockfd is valid, this should close it all up */
|
2008-02-26 21:32:20 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
reset();
|
2008-03-26 11:35:09 -04:00
|
|
|
return -1;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (waiting != WAITING_SOCK_CONNECT)
|
|
|
|
{
|
2008-07-10 12:29:18 -04:00
|
|
|
rslog(RSL_DEBUG_BASIC, pqissludpzone,
|
2007-11-14 22:18:48 -05:00
|
|
|
"pqissludp::Basic_Connection_Complete() Wrong Mode");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* new approach is to check for an error */
|
|
|
|
/* check for an error */
|
|
|
|
int err;
|
|
|
|
if (0 != (err = tou_errno(sockfd)))
|
|
|
|
{
|
|
|
|
if (err == EINPROGRESS)
|
|
|
|
{
|
|
|
|
|
|
|
|
std::ostringstream out;
|
2008-07-10 12:29:18 -04:00
|
|
|
out << "pqissludp::Basic_Connection_Complete() ";
|
|
|
|
out << "EINPROGRESS: cert: " << PeerId();
|
|
|
|
rslog(RSL_DEBUG_BASIC, pqissludpzone, out.str());
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
else if ((err == ENETUNREACH) || (err == ETIMEDOUT))
|
|
|
|
{
|
|
|
|
std::ostringstream out;
|
2008-07-10 12:29:18 -04:00
|
|
|
out << "pqissludp::Basic_Connection_Complete() ";
|
|
|
|
out << "ENETUNREACH/ETIMEDOUT: cert: ";
|
|
|
|
out << PeerId();
|
|
|
|
rslog(RSL_WARNING, pqissludpzone, out.str());
|
|
|
|
|
|
|
|
/* is the second one needed? */
|
|
|
|
std::ostringstream out2;
|
|
|
|
out2 << "pqissludp::Basic_Connection_Complete() ";
|
|
|
|
out2 << "Error: Connection Failed: " << err;
|
|
|
|
out2 << " - " << socket_errorType(err);
|
|
|
|
rslog(RSL_DEBUG_BASIC, pqissludpzone, out2.str());
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
reset();
|
|
|
|
|
|
|
|
// Then send unreachable message.
|
|
|
|
waiting = WAITING_FAIL_INTERFACE;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* <===================== UDP Difference *******************/
|
|
|
|
if (tou_connected(sockfd))
|
|
|
|
/* <===================== UDP Difference *******************/
|
|
|
|
{
|
2008-07-10 12:29:18 -04:00
|
|
|
std::ostringstream out;
|
|
|
|
out << "pqissludp::Basic_Connection_Complete() ";
|
|
|
|
out << "Connection Complete: cert: ";
|
|
|
|
out << PeerId();
|
|
|
|
rslog(RSL_WARNING, pqissludpzone, out.str());
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// not ready return -1;
|
2008-07-10 12:29:18 -04:00
|
|
|
rslog(RSL_DEBUG_BASIC, pqissludpzone,
|
2007-11-14 22:18:48 -05:00
|
|
|
"pqissludp::Basic_Connection_Complete() Not Yet Ready!");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* New Internal Functions required to generalise tcp/udp version
|
|
|
|
* of the programs
|
|
|
|
*/
|
|
|
|
|
|
|
|
// used everywhere
|
|
|
|
int pqissludp::net_internal_close(int fd)
|
|
|
|
{
|
2008-07-10 12:29:18 -04:00
|
|
|
rslog(RSL_ALERT, pqissludpzone,
|
2007-11-14 22:18:48 -05:00
|
|
|
"pqissludp::net_internal_close() -> tou_close()");
|
|
|
|
return tou_close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
// install udp BIO.
|
|
|
|
int pqissludp::net_internal_SSL_set_fd(SSL *ssl, int fd)
|
|
|
|
{
|
2008-07-10 12:29:18 -04:00
|
|
|
rslog(RSL_DEBUG_BASIC, pqissludpzone,
|
2007-11-14 22:18:48 -05:00
|
|
|
"pqissludp::net_internal_SSL_set_fd()");
|
|
|
|
|
|
|
|
/* create the bio's */
|
|
|
|
tou_bio =BIO_new(BIO_s_tou_socket());
|
|
|
|
|
|
|
|
/* attach the fd's to the BIO's */
|
|
|
|
BIO_set_fd(tou_bio, fd, BIO_NOCLOSE);
|
|
|
|
SSL_set_bio(ssl, tou_bio, tou_bio);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-08-12 09:42:30 -04:00
|
|
|
int pqissludp::net_internal_fcntl_nonblock(int /*fd*/)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2008-07-10 12:29:18 -04:00
|
|
|
rslog(RSL_DEBUG_BASIC, pqissludpzone,
|
2007-11-14 22:18:48 -05:00
|
|
|
"pqissludp::net_internal_fcntl_nonblock()");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* These are identical to pqinetssl version */
|
|
|
|
//int pqissludp::status()
|
|
|
|
|
|
|
|
int pqissludp::tick()
|
|
|
|
{
|
|
|
|
pqissl::tick();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// listen fns call the udpproxy.
|
|
|
|
int pqissludp::listen()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::ostringstream out;
|
2008-01-25 01:36:40 -05:00
|
|
|
out << "pqissludp::listen() (NULLOP)";
|
2008-07-10 12:29:18 -04:00
|
|
|
rslog(RSL_DEBUG_BASIC, pqissludpzone, out.str());
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
2008-01-25 01:36:40 -05:00
|
|
|
return 1; //udpproxy->listen();
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int pqissludp::stoplistening()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::ostringstream out;
|
2008-01-25 01:36:40 -05:00
|
|
|
out << "pqissludp::stoplistening() (NULLOP)";
|
2008-07-10 12:29:18 -04:00
|
|
|
rslog(RSL_DEBUG_BASIC, pqissludpzone, out.str());
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
2008-01-25 01:36:40 -05:00
|
|
|
return 1; //udpproxy->stoplistening();
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-26 21:32:20 -05:00
|
|
|
bool pqissludp::connect_parameter(uint32_t type, uint32_t value)
|
|
|
|
{
|
2008-07-10 12:29:18 -04:00
|
|
|
//std::cerr << "pqissludp::connect_parameter() type: " << type << "value: " << value << std::endl;
|
2008-02-26 21:32:20 -05:00
|
|
|
if (type == NET_PARAM_CONNECT_PERIOD)
|
|
|
|
{
|
2008-07-10 12:29:18 -04:00
|
|
|
std::ostringstream out;
|
|
|
|
out << "pqissludp::connect_parameter() Peer: " << PeerId() << " PERIOD: " << value;
|
|
|
|
rslog(RSL_WARNING, pqissludpzone, out.str());
|
2010-06-25 17:44:24 -04:00
|
|
|
|
2008-02-26 21:32:20 -05:00
|
|
|
mConnectPeriod = value;
|
2012-01-08 07:22:35 -05:00
|
|
|
std::cerr << out.str() << std::endl;
|
2008-02-26 21:32:20 -05:00
|
|
|
return true;
|
2010-06-25 17:44:24 -04:00
|
|
|
}
|
2011-07-13 18:23:40 -04:00
|
|
|
else if (type == NET_PARAM_CONNECT_FLAGS)
|
|
|
|
{
|
|
|
|
std::ostringstream out;
|
|
|
|
out << "pqissludp::connect_parameter() Peer: " << PeerId() << " FLAGS: " << value;
|
|
|
|
rslog(RSL_WARNING, pqissludpzone, out.str());
|
|
|
|
|
|
|
|
mConnectFlags = value;
|
2012-01-08 07:22:35 -05:00
|
|
|
std::cerr << out.str() << std::endl;
|
2011-07-13 18:23:40 -04:00
|
|
|
return true;
|
|
|
|
}
|
2011-07-14 10:56:33 -04:00
|
|
|
else if (type == NET_PARAM_CONNECT_BANDWIDTH)
|
|
|
|
{
|
|
|
|
std::ostringstream out;
|
|
|
|
out << "pqissludp::connect_parameter() Peer: " << PeerId() << " BANDWIDTH: " << value;
|
|
|
|
rslog(RSL_WARNING, pqissludpzone, out.str());
|
|
|
|
|
2011-07-18 14:28:20 -04:00
|
|
|
mConnectBandwidth = value;
|
2012-01-08 07:22:35 -05:00
|
|
|
std::cerr << out.str() << std::endl;
|
2011-07-14 10:56:33 -04:00
|
|
|
return true;
|
|
|
|
}
|
2010-06-25 17:44:24 -04:00
|
|
|
return pqissl::connect_parameter(type, value);
|
2008-02-26 21:32:20 -05:00
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2011-07-14 10:56:33 -04:00
|
|
|
bool pqissludp::connect_additional_address(uint32_t type, struct sockaddr_in *addr)
|
|
|
|
{
|
|
|
|
if (type == NET_PARAM_CONNECT_PROXY)
|
|
|
|
{
|
|
|
|
std::ostringstream out;
|
|
|
|
out << "pqissludp::connect_parameter() Peer: " << PeerId() << " PROXYADDR: ";
|
|
|
|
out << rs_inet_ntoa(addr->sin_addr) << ":" << ntohs(addr->sin_port);
|
|
|
|
rslog(RSL_WARNING, pqissludpzone, out.str());
|
|
|
|
|
|
|
|
mConnectProxyAddr = *addr;
|
|
|
|
|
|
|
|
std::cerr << out.str() << std::endl;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (type == NET_PARAM_CONNECT_SOURCE)
|
|
|
|
{
|
|
|
|
std::ostringstream out;
|
|
|
|
out << "pqissludp::connect_parameter() Peer: " << PeerId() << " SRCADDR: ";
|
|
|
|
out << rs_inet_ntoa(addr->sin_addr) << ":" << ntohs(addr->sin_port);
|
|
|
|
rslog(RSL_WARNING, pqissludpzone, out.str());
|
|
|
|
|
|
|
|
mConnectSrcAddr = *addr;
|
|
|
|
|
|
|
|
std::cerr << out.str() << std::endl;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return pqissl::connect_additional_address(type, addr);
|
|
|
|
}
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/********** PQI STREAMER OVERLOADING *********************************/
|
|
|
|
|
|
|
|
bool pqissludp::moretoread()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::ostringstream out;
|
|
|
|
out << "pqissludp::moretoread()";
|
|
|
|
out << " polling socket (" << sockfd << ")";
|
2008-07-10 12:29:18 -04:00
|
|
|
rslog(RSL_DEBUG_ALL, pqissludpzone, out.str());
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check for more to read first ... if nothing... check error
|
|
|
|
*/
|
|
|
|
/* <===================== UDP Difference *******************/
|
|
|
|
if (tou_maxread(sockfd))
|
|
|
|
/* <===================== UDP Difference *******************/
|
|
|
|
{
|
2008-07-10 12:29:18 -04:00
|
|
|
rslog(RSL_DEBUG_BASIC, pqissludpzone,
|
2007-11-14 22:18:48 -05:00
|
|
|
"pqissludp::moretoread() Data to Read!");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* else check the error */
|
2008-07-10 12:29:18 -04:00
|
|
|
rslog(RSL_DEBUG_ALL, pqissludpzone,
|
2007-11-14 22:18:48 -05:00
|
|
|
"pqissludp::moretoread() No Data to Read!");
|
|
|
|
|
|
|
|
int err;
|
|
|
|
if (0 != (err = tou_errno(sockfd)))
|
|
|
|
{
|
|
|
|
if ((err == EAGAIN) || (err == EINPROGRESS))
|
|
|
|
{
|
|
|
|
|
|
|
|
std::ostringstream out;
|
|
|
|
out << "pqissludp::moretoread() ";
|
2008-07-10 12:29:18 -04:00
|
|
|
out << "EAGAIN/EINPROGRESS: cert " << PeerId();
|
|
|
|
rslog(RSL_DEBUG_BASIC, pqissludpzone, out.str());
|
2007-11-14 22:18:48 -05:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
else if ((err == ENETUNREACH) || (err == ETIMEDOUT))
|
|
|
|
{
|
|
|
|
std::ostringstream out;
|
|
|
|
out << "pqissludp::moretoread() ";
|
2008-07-10 12:29:18 -04:00
|
|
|
out << "ENETUNREACH/ETIMEDOUT: cert ";
|
2008-01-25 01:36:40 -05:00
|
|
|
out << PeerId();
|
2008-07-10 12:29:18 -04:00
|
|
|
rslog(RSL_WARNING, pqissludpzone, out.str());
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
else if (err == EBADF)
|
|
|
|
{
|
|
|
|
std::ostringstream out;
|
|
|
|
out << "pqissludp::moretoread() ";
|
2008-07-10 12:29:18 -04:00
|
|
|
out << "EBADF: cert ";
|
2008-01-25 01:36:40 -05:00
|
|
|
out << PeerId();
|
2008-07-10 12:29:18 -04:00
|
|
|
rslog(RSL_WARNING, pqissludpzone, out.str());
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::ostringstream out;
|
|
|
|
out << "pqissludp::moretoread() ";
|
2008-07-10 12:29:18 -04:00
|
|
|
out << " Unknown ERROR: " << err << ": cert ";
|
2008-01-25 01:36:40 -05:00
|
|
|
out << PeerId();
|
2008-07-10 12:29:18 -04:00
|
|
|
rslog(RSL_WARNING, pqissludpzone, out.str());
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
reset();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* otherwise - not error - strange! */
|
2008-07-10 12:29:18 -04:00
|
|
|
rslog(RSL_DEBUG_BASIC, pqissludpzone,
|
2007-11-14 22:18:48 -05:00
|
|
|
"pqissludp::moretoread() No Data + No Error (really nothing)");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool pqissludp::cansend()
|
|
|
|
{
|
2008-07-10 12:29:18 -04:00
|
|
|
rslog(RSL_DEBUG_ALL, pqissludpzone,
|
2007-11-14 22:18:48 -05:00
|
|
|
"pqissludp::cansend() polling socket!");
|
|
|
|
|
|
|
|
/* <===================== UDP Difference *******************/
|
|
|
|
return (0 < tou_maxwrite(sockfd));
|
|
|
|
/* <===================== UDP Difference *******************/
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|