2007-11-14 22:18:48 -05:00
|
|
|
/*
|
2007-12-11 20:29:14 -05:00
|
|
|
* libretroshare/src/pqi pqiperson.h
|
2007-11-14 22:18:48 -05:00
|
|
|
*
|
|
|
|
* 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_PERSON_HEADER
|
|
|
|
#define MRK_PQI_PERSON_HEADER
|
|
|
|
|
|
|
|
|
|
|
|
#include "pqi/pqi.h"
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
|
|
|
|
class pqiperson;
|
|
|
|
|
|
|
|
static const int CONNECT_RECEIVED = 1;
|
|
|
|
static const int CONNECT_SUCCESS = 2;
|
|
|
|
static const int CONNECT_UNREACHABLE = 3;
|
|
|
|
static const int CONNECT_FIREWALLED = 4;
|
|
|
|
static const int CONNECT_FAILED = 5;
|
|
|
|
|
2010-06-05 15:16:39 -04:00
|
|
|
static const int HEARTBEAT_REPEAT_TIME = 5;
|
2009-12-22 05:41:19 -05:00
|
|
|
|
2012-06-23 08:10:41 -04:00
|
|
|
#include "pqi/pqiqosstreamer.h"
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2012-06-23 08:10:41 -04:00
|
|
|
class pqiconnect: public pqiQoSstreamer, public NetInterface
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
public:
|
2007-12-11 20:29:14 -05:00
|
|
|
pqiconnect(RsSerialiser *rss, NetBinInterface *ni_in)
|
2012-06-23 08:10:41 -04:00
|
|
|
:pqiQoSstreamer(rss, ni_in->PeerId(), ni_in, 0), // pqistreamer will cleanup NetInterface.
|
|
|
|
NetInterface(NULL, ni_in->PeerId()), // No need for callback
|
|
|
|
ni(ni_in)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
if (!ni_in)
|
|
|
|
{
|
|
|
|
std::cerr << "pqiconnect::pqiconnect() NetInterface == NULL, FATAL!";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~pqiconnect() { return; }
|
|
|
|
|
|
|
|
// presents a virtual NetInterface -> passes to ni.
|
2008-01-25 01:36:40 -05:00
|
|
|
virtual int connect(struct sockaddr_in raddr) { return ni->connect(raddr); }
|
2007-11-14 22:18:48 -05:00
|
|
|
virtual int listen() { return ni -> listen(); }
|
|
|
|
virtual int stoplistening() { return ni -> stoplistening(); }
|
|
|
|
virtual int reset() { return ni -> reset(); }
|
|
|
|
virtual int disconnect() { return ni -> reset(); }
|
2008-03-26 11:35:09 -04:00
|
|
|
virtual bool connect_parameter(uint32_t type, uint32_t value) { return ni -> connect_parameter(type, value);}
|
2011-07-14 10:56:33 -04:00
|
|
|
virtual bool connect_additional_address(uint32_t type, struct sockaddr_in *addr) { return ni -> connect_additional_address(type, addr);}
|
|
|
|
|
|
|
|
|
2012-01-08 17:15:19 -05:00
|
|
|
|
2009-12-14 13:11:19 -05:00
|
|
|
virtual int getConnectAddress(struct sockaddr_in &raddr){ return ni->getConnectAddress(raddr); }
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
// get the contact from the net side!
|
2007-12-11 20:29:14 -05:00
|
|
|
virtual std::string PeerId()
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
if (ni)
|
|
|
|
{
|
2007-12-11 20:29:14 -05:00
|
|
|
return ni->PeerId();
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-12-11 20:29:14 -05:00
|
|
|
return PQInterface::PeerId();
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// to check if our interface.
|
|
|
|
virtual bool thisNetInterface(NetInterface *ni_in) { return (ni_in == ni); }
|
2012-01-08 11:28:44 -05:00
|
|
|
protected:
|
2007-11-14 22:18:48 -05:00
|
|
|
NetBinInterface *ni;
|
|
|
|
protected:
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-01-25 01:36:40 -05:00
|
|
|
class pqipersongrp;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
class pqiperson: public PQInterface
|
|
|
|
{
|
|
|
|
public:
|
2008-01-25 01:36:40 -05:00
|
|
|
pqiperson(std::string id, pqipersongrp *ppg);
|
2007-11-14 22:18:48 -05:00
|
|
|
virtual ~pqiperson(); // must clean up children.
|
|
|
|
|
|
|
|
// control of the connection.
|
|
|
|
int reset();
|
2008-01-28 00:40:32 -05:00
|
|
|
int listen();
|
|
|
|
int stoplistening();
|
2011-07-14 10:56:33 -04:00
|
|
|
|
|
|
|
int connect(uint32_t type, struct sockaddr_in raddr,
|
|
|
|
struct sockaddr_in &proxyaddr, struct sockaddr_in &srcaddr,
|
|
|
|
uint32_t delay, uint32_t period, uint32_t timeout, uint32_t flags, uint32_t bandwidth);
|
|
|
|
|
2009-12-22 05:41:19 -05:00
|
|
|
int receiveHeartbeat();
|
2007-11-14 22:18:48 -05:00
|
|
|
// add in connection method.
|
2008-01-25 01:36:40 -05:00
|
|
|
int addChildInterface(uint32_t type, pqiconnect *pqi);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
// The PQInterface interface.
|
2011-09-04 16:01:30 -04:00
|
|
|
virtual int SendItem(RsItem *,uint32_t& serialized_size);
|
|
|
|
virtual int SendItem(RsItem *item)
|
|
|
|
{
|
|
|
|
std::cerr << "Warning pqiperson::sendItem(RsItem*) should not be called. Plz call SendItem(RsItem *,uint32_t& serialized_size) instead." << std::endl;
|
|
|
|
uint32_t serialized_size ;
|
|
|
|
return SendItem(item,serialized_size) ;
|
|
|
|
}
|
2007-12-11 20:29:14 -05:00
|
|
|
virtual RsItem *GetItem();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
virtual int status();
|
|
|
|
virtual int tick();
|
|
|
|
|
|
|
|
// overloaded callback function for the child - notify of a change.
|
|
|
|
int notifyEvent(NetInterface *ni, int event);
|
|
|
|
|
|
|
|
// PQInterface for rate control overloaded....
|
2012-06-21 21:35:32 -04:00
|
|
|
virtual int getQueueSize(bool in);
|
|
|
|
virtual void getRates(RsBwRates &rates);
|
2007-11-14 22:18:48 -05:00
|
|
|
virtual float getRate(bool in);
|
|
|
|
virtual void setMaxRate(bool in, float val);
|
2012-01-08 17:15:19 -05:00
|
|
|
virtual void setRateCap(float val_in, float val_out);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-12-13 16:59:26 -05:00
|
|
|
pqiconnect *getKid(uint32_t type);
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
private:
|
|
|
|
|
2008-01-25 01:36:40 -05:00
|
|
|
std::map<uint32_t, pqiconnect *> kids;
|
2007-11-14 22:18:48 -05:00
|
|
|
bool active;
|
|
|
|
pqiconnect *activepqi;
|
|
|
|
bool inConnectAttempt;
|
|
|
|
int waittimes;
|
2009-12-22 05:41:19 -05:00
|
|
|
time_t lastHeartbeatReceived;//use to track connection failure
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
private: /* Helper functions */
|
|
|
|
|
|
|
|
|
2008-01-25 01:36:40 -05:00
|
|
|
pqipersongrp *pqipg; /* parent for callback */
|
2007-11-14 22:18:48 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|