mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-29 01:16:20 -05:00
Added a thread per active peer - to reduce RTT and increase throughout.
* Added pqithreadstreamer, tweaked pqistreamer to support derivation. * Shifted RTT from p3Service to p3FastService. * Disabled lots of debug. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.6-initdev@6787 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
a7dd9ad9e3
commit
b587301b5a
@ -352,6 +352,7 @@ HEADERS += pqi/authssl.h \
|
||||
pqi/pqisslproxy.h \
|
||||
pqi/pqistore.h \
|
||||
pqi/pqistreamer.h \
|
||||
pqi/pqithreadstreamer.h \
|
||||
pqi/pqiqosstreamer.h \
|
||||
pqi/sslfns.h \
|
||||
pqi/pqinetstatebox.h
|
||||
@ -473,6 +474,7 @@ SOURCES += pqi/authgpg.cc \
|
||||
pqi/pqisslproxy.cc \
|
||||
pqi/pqistore.cc \
|
||||
pqi/pqistreamer.cc \
|
||||
pqi/pqithreadstreamer.cc \
|
||||
pqi/pqiqosstreamer.cc \
|
||||
pqi/sslfns.cc \
|
||||
pqi/pqinetstatebox.cc
|
||||
|
@ -74,10 +74,6 @@ const uint32_t MIN_TIME_BETWEEN_NET_RESET = 5;
|
||||
* #define NETMGR_DEBUG_STATEBOX 1
|
||||
***/
|
||||
|
||||
#define NETMGR_DEBUG 1
|
||||
#define NETMGR_DEBUG_RESET 1
|
||||
#define NETMGR_DEBUG_TICK 1
|
||||
#define NETMGR_DEBUG_STATEBOX 1
|
||||
|
||||
pqiNetStatus::pqiNetStatus()
|
||||
:mLocalAddrOk(false), mExtAddrOk(false), mExtAddrStableOk(false),
|
||||
|
@ -210,6 +210,7 @@ class PQInterface: public RateInterface
|
||||
* Retrieve RsItem from a facility
|
||||
*/
|
||||
virtual RsItem *GetItem() = 0;
|
||||
virtual bool RecvItem(RsItem *item) { return false; } /* alternative for for GetItem(), when we want to push */
|
||||
|
||||
/**
|
||||
* also there are tick + person id functions.
|
||||
|
@ -295,8 +295,6 @@ int pqihandler::SendRsRawItem(RsRawItem *ns)
|
||||
return queueOutRsItem(ns) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// inputs. This is a very basic
|
||||
// system that is completely biased and slow...
|
||||
// someone please fix.
|
||||
|
@ -35,10 +35,9 @@ const int pqipersonzone = 82371;
|
||||
* #define PERSON_DEBUG 1
|
||||
****/
|
||||
|
||||
#define PERSON_DEBUG 1
|
||||
|
||||
pqiperson::pqiperson(std::string id, pqipersongrp *pg)
|
||||
:PQInterface(id), active(false), activepqi(NULL),
|
||||
:PQInterface(id), mNotifyMtx("pqiperson-notify"), mPersonMtx("pqiperson"),
|
||||
active(false), activepqi(NULL),
|
||||
inConnectAttempt(false), waittimes(0),
|
||||
pqipg(pg)
|
||||
{
|
||||
@ -50,6 +49,8 @@ pqiperson::pqiperson(std::string id, pqipersongrp *pg)
|
||||
|
||||
pqiperson::~pqiperson()
|
||||
{
|
||||
RsStackMutex stack(mPersonMtx); /**** LOCK MUTEX ****/
|
||||
|
||||
// clean up the children.
|
||||
std::map<uint32_t, pqiconnect *>::iterator it;
|
||||
for(it = kids.begin(); it != kids.end(); it++)
|
||||
@ -64,6 +65,8 @@ pqiperson::~pqiperson()
|
||||
// The PQInterface interface.
|
||||
int pqiperson::SendItem(RsItem *i,uint32_t& serialized_size)
|
||||
{
|
||||
RsStackMutex stack(mPersonMtx); /**** LOCK MUTEX ****/
|
||||
|
||||
std::string out = "pqiperson::SendItem()";
|
||||
if (active)
|
||||
{
|
||||
@ -86,14 +89,27 @@ int pqiperson::SendItem(RsItem *i,uint32_t& serialized_size)
|
||||
|
||||
RsItem *pqiperson::GetItem()
|
||||
{
|
||||
RsStackMutex stack(mPersonMtx); /**** LOCK MUTEX ****/
|
||||
|
||||
if (active)
|
||||
return activepqi -> GetItem();
|
||||
// else not possible.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool pqiperson::RecvItem(RsItem *item)
|
||||
{
|
||||
std::cerr << "pqiperson::RecvItem()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
return pqipg->recvItem((RsRawItem *) item);
|
||||
}
|
||||
|
||||
|
||||
int pqiperson::status()
|
||||
{
|
||||
RsStackMutex stack(mPersonMtx); /**** LOCK MUTEX ****/
|
||||
|
||||
if (active)
|
||||
return activepqi -> status();
|
||||
return -1;
|
||||
@ -101,6 +117,8 @@ int pqiperson::status()
|
||||
|
||||
int pqiperson::receiveHeartbeat()
|
||||
{
|
||||
RsStackMutex stack(mPersonMtx); /**** LOCK MUTEX ****/
|
||||
|
||||
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::receiveHeartbeat() from peer : " + PeerId());
|
||||
lastHeartbeatReceived = time(NULL);
|
||||
|
||||
@ -110,61 +128,68 @@ int pqiperson::receiveHeartbeat()
|
||||
// tick......
|
||||
int pqiperson::tick()
|
||||
{
|
||||
//if lastHeartbeatReceived is 0, it might be not activated so don't do a net reset.
|
||||
if (active && (lastHeartbeatReceived != 0) &&
|
||||
(time(NULL) - lastHeartbeatReceived) > HEARTBEAT_REPEAT_TIME * 5)
|
||||
int activeTick = 0;
|
||||
{
|
||||
int ageLastIncoming = time(NULL) - activepqi->getLastIncomingTS();
|
||||
std::string out = "pqiperson::tick() WARNING No heartbeat from: " + PeerId();
|
||||
//out << " assume dead. calling pqissl::reset(), LastHeartbeat was: ";
|
||||
rs_sprintf_append(out, " LastHeartbeat was: %ld secs ago", time(NULL) - lastHeartbeatReceived);
|
||||
rs_sprintf_append(out, " LastIncoming was: %d secs ago", ageLastIncoming);
|
||||
pqioutput(PQL_WARNING, pqipersonzone, out);
|
||||
|
||||
#define NO_PACKET_TIMEOUT 60
|
||||
|
||||
if (ageLastIncoming > NO_PACKET_TIMEOUT)
|
||||
RsStackMutex stack(mPersonMtx); /**** LOCK MUTEX ****/
|
||||
|
||||
//if lastHeartbeatReceived is 0, it might be not activated so don't do a net reset.
|
||||
if (active && (lastHeartbeatReceived != 0) &&
|
||||
(time(NULL) - lastHeartbeatReceived) > HEARTBEAT_REPEAT_TIME * 5)
|
||||
{
|
||||
out = "pqiperson::tick() " + PeerId();
|
||||
out += " No Heartbeat & No Packets -> assume dead. calling pqissl::reset()";
|
||||
int ageLastIncoming = time(NULL) - activepqi->getLastIncomingTS();
|
||||
std::string out = "pqiperson::tick() WARNING No heartbeat from: " + PeerId();
|
||||
//out << " assume dead. calling pqissl::reset(), LastHeartbeat was: ";
|
||||
rs_sprintf_append(out, " LastHeartbeat was: %ld secs ago", time(NULL) - lastHeartbeatReceived);
|
||||
rs_sprintf_append(out, " LastIncoming was: %d secs ago", ageLastIncoming);
|
||||
pqioutput(PQL_WARNING, pqipersonzone, out);
|
||||
|
||||
this->reset();
|
||||
|
||||
#define NO_PACKET_TIMEOUT 60
|
||||
|
||||
if (ageLastIncoming > NO_PACKET_TIMEOUT)
|
||||
{
|
||||
out = "pqiperson::tick() " + PeerId();
|
||||
out += " No Heartbeat & No Packets -> assume dead. calling pqissl::reset()";
|
||||
pqioutput(PQL_WARNING, pqipersonzone, out);
|
||||
|
||||
this->reset();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
{
|
||||
std::string out = "pqiperson::tick() Id: " + PeerId() + " ";
|
||||
if (active)
|
||||
out += "***Active***";
|
||||
else
|
||||
out += ">>InActive<<";
|
||||
|
||||
out += "\n";
|
||||
rs_sprintf_append(out, "Activepqi: %p inConnectAttempt: ", activepqi);
|
||||
|
||||
if (inConnectAttempt)
|
||||
out += "In Connection Attempt";
|
||||
else
|
||||
out += " Not Connecting ";
|
||||
out += "\n";
|
||||
|
||||
// tick the children.
|
||||
std::map<uint32_t, pqiconnect *>::iterator it;
|
||||
for(it = kids.begin(); it != kids.end(); it++)
|
||||
{
|
||||
if (0 < (it->second) -> tick())
|
||||
{
|
||||
activeTick = 1;
|
||||
}
|
||||
rs_sprintf_append(out, "\tTicking Child: %d\n", it->first);
|
||||
}
|
||||
|
||||
pqioutput(PQL_DEBUG_ALL, pqipersonzone, out);
|
||||
} // end of pqioutput.
|
||||
}
|
||||
|
||||
int activeTick = 0;
|
||||
|
||||
{
|
||||
std::string out = "pqiperson::tick() Id: " + PeerId() + " ";
|
||||
if (active)
|
||||
out += "***Active***";
|
||||
else
|
||||
out += ">>InActive<<";
|
||||
|
||||
out += "\n";
|
||||
rs_sprintf_append(out, "Activepqi: %p inConnectAttempt: ", activepqi);
|
||||
|
||||
if (inConnectAttempt)
|
||||
out += "In Connection Attempt";
|
||||
else
|
||||
out += " Not Connecting ";
|
||||
out += "\n";
|
||||
|
||||
// tick the children.
|
||||
std::map<uint32_t, pqiconnect *>::iterator it;
|
||||
for(it = kids.begin(); it != kids.end(); it++)
|
||||
{
|
||||
if (0 < (it->second) -> tick())
|
||||
{
|
||||
activeTick = 1;
|
||||
}
|
||||
rs_sprintf_append(out, "\tTicking Child: %d\n", it->first);
|
||||
}
|
||||
|
||||
pqioutput(PQL_DEBUG_ALL, pqipersonzone, out);
|
||||
} // end of pqioutput.
|
||||
// handle Notify Events that were generated.
|
||||
processNotifyEvents();
|
||||
|
||||
return activeTick;
|
||||
}
|
||||
@ -172,8 +197,60 @@ int pqiperson::tick()
|
||||
// callback function for the child - notify of a change.
|
||||
// This is only used for out-of-band info....
|
||||
// otherwise could get dangerous loops.
|
||||
// - Actually, now we have - must store and process later.
|
||||
int pqiperson::notifyEvent(NetInterface *ni, int newState, const struct sockaddr_storage &remote_peer_address)
|
||||
{
|
||||
if (mPersonMtx.trylock())
|
||||
{
|
||||
handleNotifyEvent_locked(ni, newState, remote_peer_address);
|
||||
|
||||
mPersonMtx.unlock();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
RsStackMutex stack(mNotifyMtx); /**** LOCK MUTEX ****/
|
||||
|
||||
mNotifyQueue.push_back(NotifyData(ni, newState, remote_peer_address));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void pqiperson::processNotifyEvents()
|
||||
{
|
||||
NetInterface *ni;
|
||||
int state;
|
||||
struct sockaddr_storage addr;
|
||||
|
||||
while(1)
|
||||
{
|
||||
{
|
||||
RsStackMutex stack(mNotifyMtx); /**** LOCK MUTEX ****/
|
||||
|
||||
if (mNotifyQueue.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
NotifyData &data = mNotifyQueue.front();
|
||||
ni = data.mNi;
|
||||
state = data.mState;
|
||||
addr = data.mAddr;
|
||||
|
||||
mNotifyQueue.pop_front();
|
||||
}
|
||||
|
||||
RsStackMutex stack(mPersonMtx); /**** LOCK MUTEX ****/
|
||||
handleNotifyEvent_locked(ni, state, addr);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int pqiperson::handleNotifyEvent_locked(NetInterface *ni, int newState, const struct sockaddr_storage &remote_peer_address)
|
||||
{
|
||||
|
||||
{
|
||||
std::string out = "pqiperson::notifyEvent() Id: " + PeerId() + "\n";
|
||||
rs_sprintf_append(out, "Message: %d from: %p\n", newState, ni);
|
||||
@ -243,6 +320,8 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState, const struct sockadd
|
||||
activepqi = pqi;
|
||||
inConnectAttempt = false;
|
||||
|
||||
activepqi->start(); // STARTUP THREAD.
|
||||
|
||||
/* reset all other children? (clear up long UDP attempt) */
|
||||
for(it = kids.begin(); it != kids.end(); it++)
|
||||
{
|
||||
@ -270,6 +349,7 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState, const struct sockadd
|
||||
{
|
||||
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::notifyEvent() Id: " + PeerId() + " CONNECT_FAILED->marking so!");
|
||||
|
||||
activepqi->stop(); // STOP THREAD.
|
||||
active = false;
|
||||
activepqi = NULL;
|
||||
}
|
||||
@ -302,11 +382,14 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState, const struct sockadd
|
||||
|
||||
int pqiperson::reset()
|
||||
{
|
||||
RsStackMutex stack(mPersonMtx); /**** LOCK MUTEX ****/
|
||||
|
||||
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::reset() resetting all pqiconnect for Id: " + PeerId());
|
||||
|
||||
std::map<uint32_t, pqiconnect *>::iterator it;
|
||||
for(it = kids.begin(); it != kids.end(); it++)
|
||||
{
|
||||
(it->second) -> stop(); // STOP THREAD.
|
||||
(it->second) -> reset();
|
||||
}
|
||||
|
||||
@ -317,8 +400,29 @@ int pqiperson::reset()
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pqiperson::fullstopthreads()
|
||||
{
|
||||
RsStackMutex stack(mPersonMtx); /**** LOCK MUTEX ****/
|
||||
|
||||
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::fullstopthreads() for Id: " + PeerId());
|
||||
|
||||
std::map<uint32_t, pqiconnect *>::iterator it;
|
||||
for(it = kids.begin(); it != kids.end(); it++)
|
||||
{
|
||||
(it->second) -> fullstop(); // WAIT FOR THREAD TO STOP.
|
||||
}
|
||||
|
||||
activepqi = NULL;
|
||||
active = false;
|
||||
lastHeartbeatReceived = 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pqiperson::addChildInterface(uint32_t type, pqiconnect *pqi)
|
||||
{
|
||||
RsStackMutex stack(mPersonMtx); /**** LOCK MUTEX ****/
|
||||
|
||||
{
|
||||
std::string out;
|
||||
rs_sprintf(out, "pqiperson::addChildInterface() : Id %s %u", PeerId().c_str(), type);
|
||||
@ -335,6 +439,8 @@ int pqiperson::addChildInterface(uint32_t type, pqiconnect *pqi)
|
||||
|
||||
int pqiperson::listen()
|
||||
{
|
||||
RsStackMutex stack(mPersonMtx); /**** LOCK MUTEX ****/
|
||||
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, "pqiperson::listen() Id: " + PeerId());
|
||||
|
||||
if (!active)
|
||||
@ -352,6 +458,8 @@ int pqiperson::listen()
|
||||
|
||||
int pqiperson::stoplistening()
|
||||
{
|
||||
RsStackMutex stack(mPersonMtx); /**** LOCK MUTEX ****/
|
||||
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, "pqiperson::stoplistening() Id: " + PeerId());
|
||||
|
||||
std::map<uint32_t, pqiconnect *>::iterator it;
|
||||
@ -368,6 +476,8 @@ int pqiperson::connect(uint32_t type, const struct sockaddr_storage &raddr,
|
||||
uint32_t delay, uint32_t period, uint32_t timeout, uint32_t flags, uint32_t bandwidth,
|
||||
const std::string &domain_addr, uint16_t domain_port)
|
||||
{
|
||||
RsStackMutex stack(mPersonMtx); /**** LOCK MUTEX ****/
|
||||
|
||||
#ifdef PERSON_DEBUG
|
||||
#endif
|
||||
{
|
||||
@ -413,7 +523,7 @@ int pqiperson::connect(uint32_t type, const struct sockaddr_storage &raddr,
|
||||
#ifdef PERSON_DEBUG
|
||||
std::cerr << "pqiperson::connect() WARNING, clearing rate cap" << std::endl;
|
||||
#endif
|
||||
setRateCap(0,0);
|
||||
setRateCap_locked(0,0);
|
||||
|
||||
#ifdef PERSON_DEBUG
|
||||
std::cerr << "pqiperson::connect() setting connect_parameters" << std::endl;
|
||||
@ -444,25 +554,10 @@ int pqiperson::connect(uint32_t type, const struct sockaddr_storage &raddr,
|
||||
}
|
||||
|
||||
|
||||
pqiconnect *pqiperson::getKid(uint32_t type)
|
||||
{
|
||||
std::map<uint32_t, pqiconnect *>::iterator it;
|
||||
|
||||
if (kids.empty()) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
it = kids.find(type);
|
||||
if (it == kids.end())
|
||||
{
|
||||
return NULL;
|
||||
} else {
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
|
||||
void pqiperson::getRates(RsBwRates &rates)
|
||||
{
|
||||
RsStackMutex stack(mPersonMtx); /**** LOCK MUTEX ****/
|
||||
|
||||
// get the rate from the active one.
|
||||
if ((!active) || (activepqi == NULL))
|
||||
return;
|
||||
@ -471,6 +566,8 @@ void pqiperson::getRates(RsBwRates &rates)
|
||||
|
||||
int pqiperson::getQueueSize(bool in)
|
||||
{
|
||||
RsStackMutex stack(mPersonMtx); /**** LOCK MUTEX ****/
|
||||
|
||||
// get the rate from the active one.
|
||||
if ((!active) || (activepqi == NULL))
|
||||
return 0;
|
||||
@ -480,6 +577,8 @@ int pqiperson::getQueueSize(bool in)
|
||||
|
||||
float pqiperson::getRate(bool in)
|
||||
{
|
||||
RsStackMutex stack(mPersonMtx); /**** LOCK MUTEX ****/
|
||||
|
||||
// get the rate from the active one.
|
||||
if ((!active) || (activepqi == NULL))
|
||||
return 0;
|
||||
@ -488,6 +587,8 @@ float pqiperson::getRate(bool in)
|
||||
|
||||
void pqiperson::setMaxRate(bool in, float val)
|
||||
{
|
||||
RsStackMutex stack(mPersonMtx); /**** LOCK MUTEX ****/
|
||||
|
||||
// set to all of them. (and us)
|
||||
PQInterface::setMaxRate(in, val);
|
||||
// clean up the children.
|
||||
@ -499,6 +600,12 @@ void pqiperson::setMaxRate(bool in, float val)
|
||||
}
|
||||
|
||||
void pqiperson::setRateCap(float val_in, float val_out)
|
||||
{
|
||||
RsStackMutex stack(mPersonMtx); /**** LOCK MUTEX ****/
|
||||
return setRateCap_locked(val_in, val_out);
|
||||
}
|
||||
|
||||
void pqiperson::setRateCap_locked(float val_in, float val_out)
|
||||
{
|
||||
// set to all of them. (and us)
|
||||
PQInterface::setRateCap(val_in, val_out);
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
|
||||
#include "pqi/pqi.h"
|
||||
#include "util/rsnet.h"
|
||||
|
||||
#include <list>
|
||||
|
||||
@ -44,12 +45,13 @@ static const int CONNECT_FAILED = 5;
|
||||
static const int HEARTBEAT_REPEAT_TIME = 5;
|
||||
|
||||
#include "pqi/pqiqosstreamer.h"
|
||||
#include "pqi/pqithreadstreamer.h"
|
||||
|
||||
class pqiconnect: public pqiQoSstreamer, public NetInterface
|
||||
{
|
||||
public:
|
||||
pqiconnect(RsSerialiser *rss, NetBinInterface *ni_in)
|
||||
:pqiQoSstreamer(rss, ni_in->PeerId(), ni_in, 0), // pqistreamer will cleanup NetInterface.
|
||||
pqiconnect(PQInterface *parent, RsSerialiser *rss, NetBinInterface *ni_in)
|
||||
:pqiQoSstreamer(parent, rss, ni_in->PeerId(), ni_in, 0), // pqistreamer will cleanup NetInterface.
|
||||
NetInterface(NULL, ni_in->PeerId()), // No need for callback
|
||||
ni(ni_in)
|
||||
{
|
||||
@ -75,7 +77,6 @@ virtual bool connect_parameter(uint32_t type, std::string value) { return ni ->
|
||||
virtual bool connect_additional_address(uint32_t type, const struct sockaddr_storage &addr) { return ni -> connect_additional_address(type, addr);}
|
||||
|
||||
|
||||
|
||||
virtual int getConnectAddress(struct sockaddr_storage &raddr){ return ni->getConnectAddress(raddr); }
|
||||
|
||||
// get the contact from the net side!
|
||||
@ -101,6 +102,25 @@ protected:
|
||||
|
||||
class pqipersongrp;
|
||||
|
||||
|
||||
class NotifyData
|
||||
{
|
||||
public:
|
||||
NotifyData()
|
||||
:mNi(NULL), mState(0)
|
||||
{
|
||||
sockaddr_storage_clear(mAddr);
|
||||
}
|
||||
|
||||
NotifyData(NetInterface *ni, int state, const struct sockaddr_storage &addr)
|
||||
:mNi(ni), mState(state), mAddr(addr) { return; }
|
||||
|
||||
NetInterface *mNi;
|
||||
int mState;
|
||||
struct sockaddr_storage mAddr;
|
||||
};
|
||||
|
||||
|
||||
class pqiperson: public PQInterface
|
||||
{
|
||||
public:
|
||||
@ -117,6 +137,8 @@ int connect(uint32_t type, const struct sockaddr_storage &raddr,
|
||||
uint32_t delay, uint32_t period, uint32_t timeout, uint32_t flags, uint32_t bandwidth,
|
||||
const std::string &domain_addr, uint16_t domain_port);
|
||||
|
||||
int fullstopthreads();
|
||||
|
||||
int receiveHeartbeat();
|
||||
// add in connection method.
|
||||
int addChildInterface(uint32_t type, pqiconnect *pqi);
|
||||
@ -130,6 +152,7 @@ virtual int SendItem(RsItem *item)
|
||||
return SendItem(item,serialized_size) ;
|
||||
}
|
||||
virtual RsItem *GetItem();
|
||||
virtual bool RecvItem(RsItem *item);
|
||||
|
||||
virtual int status();
|
||||
virtual int tick();
|
||||
@ -144,10 +167,20 @@ virtual float getRate(bool in);
|
||||
virtual void setMaxRate(bool in, float val);
|
||||
virtual void setRateCap(float val_in, float val_out);
|
||||
|
||||
pqiconnect *getKid(uint32_t type);
|
||||
|
||||
private:
|
||||
|
||||
void processNotifyEvents();
|
||||
int handleNotifyEvent_locked(NetInterface *ni, int event, const struct sockaddr_storage &addr);
|
||||
|
||||
RsMutex mNotifyMtx; /**** LOCKS Notify Queue ****/
|
||||
|
||||
std::list<NotifyData> mNotifyQueue;
|
||||
|
||||
RsMutex mPersonMtx; /**** LOCKS below ****/
|
||||
|
||||
void setRateCap_locked(float val_in, float val_out);
|
||||
|
||||
std::map<uint32_t, pqiconnect *> kids;
|
||||
bool active;
|
||||
pqiconnect *activepqi;
|
||||
|
@ -56,6 +56,21 @@ static std::list<std::string> waitingIds;
|
||||
* pqilistener and when accessing pqihandlers data.
|
||||
*/
|
||||
|
||||
|
||||
// New speedy recv.
|
||||
bool pqipersongrp::RecvRsRawItem(RsRawItem *item)
|
||||
{
|
||||
std::cerr << "pqipersongrp::RecvRsRawItem()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
p3ServiceServer::recvItem(item);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// handle the tunnel services.
|
||||
int pqipersongrp::tickServiceRecv()
|
||||
{
|
||||
@ -433,6 +448,7 @@ int pqipersongrp::removePeer(std::string id)
|
||||
p -> stoplistening();
|
||||
pqioutput(PQL_WARNING, pqipersongrpzone, "pqipersongrp::removePeer() => reset() called before deleting person");
|
||||
p -> reset();
|
||||
p -> fullstopthreads();
|
||||
delete p;
|
||||
mods.erase(it);
|
||||
}
|
||||
@ -679,7 +695,7 @@ pqiperson * pqipersongrpDummy::locked_createPerson(std::string id, pqilistener *
|
||||
RsSerialiser *rss = new RsSerialiser();
|
||||
rss->addSerialType(new RsServiceSerialiser());
|
||||
|
||||
pqiconnect *pqic = new pqiconnect(rss, d1);
|
||||
pqiconnect *pqic = new pqiconnect(pqip, rss, d1);
|
||||
|
||||
pqip -> addChildInterface(PQI_CONNECT_TCP, pqic);
|
||||
|
||||
@ -689,7 +705,7 @@ pqiperson * pqipersongrpDummy::locked_createPerson(std::string id, pqilistener *
|
||||
RsSerialiser *rss2 = new RsSerialiser();
|
||||
rss2->addSerialType(new RsServiceSerialiser());
|
||||
|
||||
pqiconnect *pqic2 = new pqiconnect(rss2, d2);
|
||||
pqiconnect *pqic2 = new pqiconnect(pqip, rss2, d2);
|
||||
|
||||
pqip -> addChildInterface(PQI_CONNECT_UDP, pqic2);
|
||||
|
||||
|
@ -80,6 +80,10 @@ int connectPeer(std::string id
|
||||
#endif
|
||||
);
|
||||
|
||||
// New speedy recv.
|
||||
virtual bool RecvRsRawItem(RsRawItem *item);
|
||||
|
||||
|
||||
/* Work-around to dodgy pointer stuff */
|
||||
int tagHeartbeatRecvd(std::string id);
|
||||
|
||||
|
@ -25,8 +25,8 @@
|
||||
|
||||
#include "pqiqosstreamer.h"
|
||||
|
||||
pqiQoSstreamer::pqiQoSstreamer(RsSerialiser *rss, std::string peerid, BinInterface *bio_in, int bio_flagsin)
|
||||
: pqistreamer(rss,peerid,bio_in,bio_flagsin), pqiQoS(PQI_QOS_STREAMER_MAX_LEVELS, PQI_QOS_STREAMER_ALPHA)
|
||||
pqiQoSstreamer::pqiQoSstreamer(PQInterface *parent, RsSerialiser *rss, std::string peerid, BinInterface *bio_in, int bio_flagsin)
|
||||
: pqithreadstreamer(parent,rss,peerid,bio_in,bio_flagsin), pqiQoS(PQI_QOS_STREAMER_MAX_LEVELS, PQI_QOS_STREAMER_ALPHA)
|
||||
{
|
||||
_total_item_size = 0 ;
|
||||
_total_item_count = 0 ;
|
||||
|
@ -26,12 +26,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "pqiqos.h"
|
||||
#include "pqistreamer.h"
|
||||
#include "pqithreadstreamer.h"
|
||||
|
||||
class pqiQoSstreamer: public pqistreamer, public pqiQoS
|
||||
class pqiQoSstreamer: public pqithreadstreamer, public pqiQoS
|
||||
{
|
||||
public:
|
||||
pqiQoSstreamer(RsSerialiser *rss, std::string peerid, BinInterface *bio_in, int bio_flagsin);
|
||||
pqiQoSstreamer(PQInterface *parent, RsSerialiser *rss, std::string peerid, BinInterface *bio_in, int bio_flagsin);
|
||||
|
||||
static const uint32_t PQI_QOS_STREAMER_MAX_LEVELS = 10 ;
|
||||
static const float PQI_QOS_STREAMER_ALPHA = 2.0 ;
|
||||
|
@ -1316,6 +1316,9 @@ int pqissl::Authorise_SSL_Connection()
|
||||
/* This function is public, and callable from pqilistener - so must be mutex protected */
|
||||
int pqissl::accept(SSL *ssl, int fd, const struct sockaddr_storage &foreign_addr) // initiate incoming connection.
|
||||
{
|
||||
std::cerr << "pqissl::accept()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
RsStackMutex stack(mSslMtx); /**** LOCKED MUTEX ****/
|
||||
|
||||
return accept_locked(ssl, fd, foreign_addr);
|
||||
@ -1476,6 +1479,9 @@ int pqissl::accept_locked(SSL *ssl, int fd, const struct sockaddr_storage &forei
|
||||
active = true;
|
||||
waiting = WAITING_NOT;
|
||||
|
||||
std::cerr << "pqissl::accept_locked() connection complete - notifying parent";
|
||||
std::cerr << std::endl;
|
||||
|
||||
// Notify the pqiperson.... (Both Connect/Receive)
|
||||
if (parent())
|
||||
{
|
||||
@ -1770,7 +1776,7 @@ bool pqissl::moretoread(uint32_t usec)
|
||||
FD_ZERO(&ExceptFDs);
|
||||
|
||||
FD_SET(sockfd, &ReadFDs);
|
||||
FD_SET(sockfd, &WriteFDs);
|
||||
// Dont set WriteFDs.
|
||||
FD_SET(sockfd, &ExceptFDs);
|
||||
|
||||
struct timeval timeout;
|
||||
@ -1797,22 +1803,6 @@ bool pqissl::moretoread(uint32_t usec)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (FD_ISSET(sockfd, &WriteFDs))
|
||||
{
|
||||
#ifdef PQISSL_DEBUG
|
||||
// write can work.
|
||||
rslog(RSL_DEBUG_ALL, pqisslzone,
|
||||
"pqissl::moretoread() Can Write!");
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef PQISSL_DEBUG
|
||||
// write can work.
|
||||
rslog(RSL_DEBUG_BASIC, pqisslzone,
|
||||
"pqissl::moretoread() Can *NOT* Write!");
|
||||
#endif
|
||||
}
|
||||
|
||||
if (FD_ISSET(sockfd, &ReadFDs))
|
||||
{
|
||||
@ -1849,7 +1839,7 @@ bool pqissl::cansend(uint32_t usec)
|
||||
FD_ZERO(&WriteFDs);
|
||||
FD_ZERO(&ExceptFDs);
|
||||
|
||||
FD_SET(sockfd, &ReadFDs);
|
||||
// Dont Set ReadFDs.
|
||||
FD_SET(sockfd, &WriteFDs);
|
||||
FD_SET(sockfd, &ExceptFDs);
|
||||
|
||||
|
@ -95,7 +95,7 @@ pqiperson * pqisslpersongrp::locked_createPerson(std::string id, pqilistener *li
|
||||
RsSerialiser *rss = new RsSerialiser();
|
||||
rss->addSerialType(new RsServiceSerialiser());
|
||||
|
||||
pqiconnect *pqisc = new pqiconnect(rss, pqis);
|
||||
pqiconnect *pqisc = new pqiconnect(pqip, rss, pqis);
|
||||
|
||||
pqip -> addChildInterface(PQI_CONNECT_HIDDEN_TCP, pqisc);
|
||||
}
|
||||
@ -118,7 +118,7 @@ pqiperson * pqisslpersongrp::locked_createPerson(std::string id, pqilistener *li
|
||||
RsSerialiser *rss = new RsSerialiser();
|
||||
rss->addSerialType(new RsServiceSerialiser());
|
||||
|
||||
pqiconnect *pqisc = new pqiconnect(rss, pqis);
|
||||
pqiconnect *pqisc = new pqiconnect(pqip, rss, pqis);
|
||||
|
||||
pqip -> addChildInterface(PQI_CONNECT_TCP, pqisc);
|
||||
|
||||
@ -128,7 +128,7 @@ pqiperson * pqisslpersongrp::locked_createPerson(std::string id, pqilistener *li
|
||||
RsSerialiser *rss2 = new RsSerialiser();
|
||||
rss2->addSerialType(new RsServiceSerialiser());
|
||||
|
||||
pqiconnect *pqiusc = new pqiconnect(rss2, pqius);
|
||||
pqiconnect *pqiusc = new pqiconnect(pqip, rss2, pqius);
|
||||
|
||||
// add a ssl + proxy interface.
|
||||
// Add Proxy First.
|
||||
|
@ -561,18 +561,24 @@ bool pqissludp::moretoread(uint32_t usec)
|
||||
{
|
||||
RsStackMutex stack(mSslMtx); /**** LOCKED MUTEX ****/
|
||||
|
||||
if (usec)
|
||||
{
|
||||
std::cerr << "pqissludp::moretoread() usec parameter not implemented";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
{
|
||||
std::string out = "pqissludp::moretoread()";
|
||||
rs_sprintf_append(out, " polling socket (%d)", sockfd);
|
||||
rslog(RSL_DEBUG_ALL, pqissludpzone, out);
|
||||
}
|
||||
|
||||
if (usec)
|
||||
{
|
||||
std::cerr << "pqissludp::moretoread() usec parameter: " << usec;
|
||||
std::cerr << std::endl;
|
||||
|
||||
if (0 < tou_maxread(sockfd))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
usleep(usec);
|
||||
}
|
||||
|
||||
/* check for more to read first ... if nothing... check error
|
||||
*/
|
||||
/* <===================== UDP Difference *******************/
|
||||
@ -631,8 +637,15 @@ bool pqissludp::cansend(uint32_t usec)
|
||||
|
||||
if (usec)
|
||||
{
|
||||
std::cerr << "pqissludp::cansend() usec parameter not implemented";
|
||||
std::cerr << "pqissludp::cansend() usec parameter: " << usec;
|
||||
std::cerr << std::endl;
|
||||
|
||||
if (0 < tou_maxwrite(sockfd))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
usleep(usec);
|
||||
}
|
||||
|
||||
rslog(RSL_DEBUG_ALL, pqissludpzone,
|
||||
|
@ -45,7 +45,6 @@ const int PQISTREAM_ABS_MAX = 100000000; /* 100 MB/sec (actually per loop) */
|
||||
#define DEBUG_PQISTREAMER 1
|
||||
***/
|
||||
|
||||
#define DEBUG_PQISTREAMER 1
|
||||
|
||||
#ifdef DEBUG_TRANSFERS
|
||||
#include "util/rsprint.h"
|
||||
@ -54,7 +53,7 @@ const int PQISTREAM_ABS_MAX = 100000000; /* 100 MB/sec (actually per loop) */
|
||||
|
||||
pqistreamer::pqistreamer(RsSerialiser *rss, std::string id, BinInterface *bio_in, int bio_flags_in)
|
||||
:PQInterface(id), mStreamerMtx("pqistreamer"),
|
||||
mRsSerialiser(rss), mBio(bio_in), mBio_flags(bio_flags_in),
|
||||
mBio(bio_in), mBio_flags(bio_flags_in), mRsSerialiser(rss),
|
||||
mPkt_wpending(NULL),
|
||||
mTotalRead(0), mTotalSent(0),
|
||||
mCurrRead(0), mCurrSent(0),
|
||||
@ -171,10 +170,10 @@ RsItem *pqistreamer::GetItem()
|
||||
// // PQInterface
|
||||
int pqistreamer::tick()
|
||||
{
|
||||
RsStackMutex stack(mStreamerMtx); /**** LOCKED MUTEX ****/
|
||||
|
||||
#ifdef DEBUG_PQISTREAMER
|
||||
{
|
||||
RsStackMutex stack(mStreamerMtx); /**** LOCKED MUTEX ****/
|
||||
std::string out = "pqistreamer::tick()\n" + PeerId();
|
||||
rs_sprintf_append(out, ": currRead/Sent: %d/%d", mCurrRead, mCurrSent);
|
||||
|
||||
@ -182,22 +181,15 @@ int pqistreamer::tick()
|
||||
}
|
||||
#endif
|
||||
|
||||
mBio->tick();
|
||||
|
||||
/* short circuit everything is bio isn't active */
|
||||
if (!(mBio->isactive()))
|
||||
if (!tick_bio())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
tick_recv(0);
|
||||
tick_send(0);
|
||||
|
||||
/* must do both, as outgoing will catch some bad sockets,
|
||||
* that incoming will not
|
||||
*/
|
||||
|
||||
handleincoming_locked();
|
||||
handleoutgoing_locked();
|
||||
|
||||
RsStackMutex stack(mStreamerMtx); /**** LOCKED MUTEX ****/
|
||||
#ifdef DEBUG_PQISTREAMER
|
||||
/* give details of the packets */
|
||||
{
|
||||
@ -234,6 +226,49 @@ int pqistreamer::tick()
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pqistreamer::tick_bio()
|
||||
{
|
||||
RsStackMutex stack(mStreamerMtx); /**** LOCKED MUTEX ****/
|
||||
mBio->tick();
|
||||
|
||||
/* short circuit everything is bio isn't active */
|
||||
if (!(mBio->isactive()))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int pqistreamer::tick_recv(uint32_t timeout)
|
||||
{
|
||||
RsStackMutex stack(mStreamerMtx); /**** LOCKED MUTEX ****/
|
||||
|
||||
if (mBio->moretoread(timeout))
|
||||
{
|
||||
handleincoming_locked();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int pqistreamer::tick_send(uint32_t timeout)
|
||||
{
|
||||
RsStackMutex stack(mStreamerMtx); /**** LOCKED MUTEX ****/
|
||||
|
||||
/* short circuit everything is bio isn't active */
|
||||
if (!(mBio->isactive()))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (mBio->cansend(timeout))
|
||||
{
|
||||
handleoutgoing_locked();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pqistreamer::status()
|
||||
{
|
||||
RsStackMutex stack(mStreamerMtx); /**** LOCKED MUTEX ****/
|
||||
|
@ -62,6 +62,11 @@ class pqistreamer: public PQInterface
|
||||
virtual void getRates(RsBwRates &rates);
|
||||
virtual int getQueueSize(bool in); // extracting data.
|
||||
protected:
|
||||
|
||||
int tick_bio();
|
||||
int tick_send(uint32_t timeout);
|
||||
int tick_recv(uint32_t timeout);
|
||||
|
||||
/* Implementation */
|
||||
|
||||
// These methods are redefined in pqiQoSstreamer
|
||||
@ -76,6 +81,10 @@ class pqistreamer: public PQInterface
|
||||
protected:
|
||||
RsMutex mStreamerMtx ; // Protects data, fns below, protected so pqiqos can use it too.
|
||||
|
||||
// Binary Interface for IO, initialisated at startup.
|
||||
BinInterface *mBio;
|
||||
unsigned int mBio_flags; // BIN_FLAGS_NO_CLOSE | BIN_FLAGS_NO_DELETE
|
||||
|
||||
private:
|
||||
int queue_outpqi_locked(RsItem *i,uint32_t& serialized_size);
|
||||
int handleincomingitem_locked(RsItem *i);
|
||||
@ -98,9 +107,6 @@ class pqistreamer: public PQInterface
|
||||
|
||||
// RsSerialiser - determines which packets can be serialised.
|
||||
RsSerialiser *mRsSerialiser;
|
||||
// Binary Interface for IO, initialisated at startup.
|
||||
BinInterface *mBio;
|
||||
unsigned int mBio_flags; // BIN_FLAGS_NO_CLOSE | BIN_FLAGS_NO_DELETE
|
||||
|
||||
void *mPkt_wpending; // storage for pending packet to write.
|
||||
int mPkt_rpend_size; // size of pkt_rpending.
|
||||
|
174
libretroshare/src/pqi/pqithreadstreamer.cc
Normal file
174
libretroshare/src/pqi/pqithreadstreamer.cc
Normal file
@ -0,0 +1,174 @@
|
||||
/*
|
||||
* pqithreadstreamer.cc
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2004-2013 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.1 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/pqithreadstreamer.h"
|
||||
|
||||
#define DEFAULT_STREAMER_TIMEOUT 10000 // 10 ms.
|
||||
#define DEFAULT_STREAMER_SLEEP 1000 // 1 ms.
|
||||
#define DEFAULT_STREAMER_IDLE_SLEEP 1000000 // 1 sec
|
||||
|
||||
pqithreadstreamer::pqithreadstreamer(PQInterface *parent, RsSerialiser *rss, std::string id, BinInterface *bio_in, int bio_flags_in)
|
||||
:pqistreamer(rss, id, bio_in, bio_flags_in), mThreadMutex("pqithreadstreamer"), mParent(parent), mTimeout(0)
|
||||
{
|
||||
mTimeout = DEFAULT_STREAMER_TIMEOUT;
|
||||
mSleepPeriod = DEFAULT_STREAMER_SLEEP;
|
||||
return;
|
||||
}
|
||||
|
||||
bool pqithreadstreamer::RecvItem(RsItem *item)
|
||||
{
|
||||
return mParent->RecvItem(item);
|
||||
}
|
||||
|
||||
int pqithreadstreamer::tick()
|
||||
{
|
||||
tick_bio();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void pqithreadstreamer::start()
|
||||
{
|
||||
{
|
||||
RsStackMutex stack(mThreadMutex);
|
||||
mToRun = true;
|
||||
}
|
||||
RsThread::start();
|
||||
}
|
||||
|
||||
void pqithreadstreamer::run()
|
||||
{
|
||||
std::cerr << "pqithreadstream::run()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mThreadMutex);
|
||||
mRunning = true;
|
||||
}
|
||||
|
||||
while(1)
|
||||
{
|
||||
{
|
||||
RsStackMutex stack(mThreadMutex);
|
||||
if (!mToRun)
|
||||
{
|
||||
std::cerr << "pqithreadstream::run() stopping";
|
||||
std::cerr << std::endl;
|
||||
|
||||
mRunning = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
data_tick();
|
||||
}
|
||||
}
|
||||
|
||||
void pqithreadstreamer::stop()
|
||||
{
|
||||
RsStackMutex stack(mThreadMutex);
|
||||
|
||||
std::cerr << "pqithreadstream::stop()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
mToRun = false;
|
||||
}
|
||||
|
||||
void pqithreadstreamer::fullstop()
|
||||
{
|
||||
stop();
|
||||
|
||||
while(1)
|
||||
{
|
||||
RsStackMutex stack(mThreadMutex);
|
||||
if (!mRunning)
|
||||
{
|
||||
std::cerr << "pqithreadstream::fullstop() complete";
|
||||
std::cerr << std::endl;
|
||||
return;
|
||||
}
|
||||
usleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
bool pqithreadstreamer::threadrunning()
|
||||
{
|
||||
RsStackMutex stack(mThreadMutex);
|
||||
return mRunning;
|
||||
}
|
||||
|
||||
|
||||
int pqithreadstreamer::data_tick()
|
||||
{
|
||||
//std::cerr << "pqithreadstream::data_tick()";
|
||||
//std::cerr << std::endl;
|
||||
|
||||
uint32_t recv_timeout = 0;
|
||||
uint32_t sleep_period = 0;
|
||||
bool isactive = false;
|
||||
{
|
||||
RsStackMutex stack(mStreamerMtx);
|
||||
recv_timeout = mTimeout;
|
||||
sleep_period = mSleepPeriod;
|
||||
isactive = mBio->isactive();
|
||||
}
|
||||
|
||||
if (!isactive)
|
||||
{
|
||||
usleep(DEFAULT_STREAMER_IDLE_SLEEP);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//std::cerr << "pqithreadstream::data_tick() tick_recv";
|
||||
//std::cerr << std::endl;
|
||||
|
||||
tick_recv(recv_timeout);
|
||||
|
||||
// Push Items, Outside of Mutex.
|
||||
RsItem *incoming = NULL;
|
||||
while((incoming = GetItem()))
|
||||
{
|
||||
RecvItem(incoming);
|
||||
}
|
||||
|
||||
//std::cerr << "pqithreadstream::data_tick() tick_send";
|
||||
//std::cerr << std::endl;
|
||||
|
||||
tick_send(0);
|
||||
|
||||
if (sleep_period)
|
||||
{
|
||||
//std::cerr << "pqithreadstream::data_tick() usleep";
|
||||
//std::cerr << std::endl;
|
||||
|
||||
usleep(sleep_period);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
62
libretroshare/src/pqi/pqithreadstreamer.h
Normal file
62
libretroshare/src/pqi/pqithreadstreamer.h
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* libretroshare/src/pqi pqithreadstreamer.h
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2004-2013 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.1 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_THREAD_STREAMER_HEADER
|
||||
#define MRK_PQI_THREAD_STREAMER_HEADER
|
||||
|
||||
#include "pqi/pqistreamer.h"
|
||||
#include "util/rsthreads.h"
|
||||
|
||||
class pqithreadstreamer: public pqistreamer, public RsThread
|
||||
{
|
||||
public:
|
||||
pqithreadstreamer(PQInterface *parent, RsSerialiser *rss, std::string peerid, BinInterface *bio_in, int bio_flagsin);
|
||||
|
||||
virtual void run();
|
||||
virtual void start();
|
||||
virtual void stop();
|
||||
virtual void fullstop();
|
||||
virtual bool threadrunning();
|
||||
|
||||
virtual bool RecvItem(RsItem *item);
|
||||
virtual int tick();
|
||||
|
||||
protected:
|
||||
|
||||
int data_tick();
|
||||
|
||||
PQInterface *mParent;
|
||||
uint32_t mTimeout;
|
||||
uint32_t mSleepPeriod;
|
||||
|
||||
private:
|
||||
/* thread variables */
|
||||
RsMutex mThreadMutex;
|
||||
bool mRunning;
|
||||
bool mToRun;
|
||||
|
||||
};
|
||||
|
||||
#endif //MRK_PQI_THREAD_STREAMER_HEADER
|
File diff suppressed because it is too large
Load Diff
@ -118,7 +118,7 @@ static double convert64bitsToTs(uint64_t bits)
|
||||
|
||||
|
||||
p3rtt::p3rtt(p3LinkMgr *lm)
|
||||
:p3Service(RS_SERVICE_TYPE_RTT), /* p3Config(CONFIG_TYPE_RTT), */ mRttMtx("p3rtt"), mLinkMgr(lm)
|
||||
:p3FastService(RS_SERVICE_TYPE_RTT), mRttMtx("p3rtt"), mLinkMgr(lm)
|
||||
{
|
||||
addSerialType(new RsRttSerialiser());
|
||||
|
||||
@ -130,7 +130,6 @@ p3rtt::p3rtt(p3LinkMgr *lm)
|
||||
|
||||
int p3rtt::tick()
|
||||
{
|
||||
processIncoming();
|
||||
sendPackets();
|
||||
|
||||
return 0;
|
||||
@ -212,57 +211,30 @@ void p3rtt::sendPingMeasurements()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int p3rtt::processIncoming()
|
||||
bool p3rtt::recvItem(RsItem *item)
|
||||
{
|
||||
/* for each packet - pass to specific handler */
|
||||
RsItem *item = NULL;
|
||||
while(NULL != (item = recvItem()))
|
||||
switch(item->PacketSubType())
|
||||
{
|
||||
switch(item->PacketSubType())
|
||||
default:
|
||||
break;
|
||||
case RS_PKT_SUBTYPE_RTT_PING:
|
||||
{
|
||||
default:
|
||||
break;
|
||||
case RS_PKT_SUBTYPE_RTT_PING:
|
||||
{
|
||||
handlePing(item);
|
||||
}
|
||||
break;
|
||||
case RS_PKT_SUBTYPE_RTT_PONG:
|
||||
{
|
||||
handlePong(item);
|
||||
}
|
||||
break;
|
||||
|
||||
#if 0
|
||||
/* THESE ARE ALL FUTURISTIC DATA TYPES */
|
||||
case RS_DATA_ITEM:
|
||||
{
|
||||
handleData(item);
|
||||
}
|
||||
break;
|
||||
|
||||
case RS_BANDWIDTH_PING_ITEM:
|
||||
{
|
||||
handleBandwidthPing(item);
|
||||
}
|
||||
break;
|
||||
|
||||
case RS_BANDWIDTH_PONG_ITEM:
|
||||
{
|
||||
handleBandwidthPong(item);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
handlePing(item);
|
||||
}
|
||||
|
||||
/* clean up */
|
||||
delete item;
|
||||
break;
|
||||
case RS_PKT_SUBTYPE_RTT_PONG:
|
||||
{
|
||||
handlePong(item);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* clean up */
|
||||
delete item;
|
||||
return true ;
|
||||
}
|
||||
|
||||
|
||||
int p3rtt::handlePing(RsItem *item)
|
||||
{
|
||||
/* cast to right type */
|
||||
|
@ -60,7 +60,7 @@ class RttPeerInfo
|
||||
* Used to test Latency.
|
||||
*/
|
||||
|
||||
class p3rtt: public RsRtt, public p3Service
|
||||
class p3rtt: public RsRtt, public p3FastService
|
||||
{
|
||||
public:
|
||||
p3rtt(p3LinkMgr *cm);
|
||||
@ -74,10 +74,10 @@ virtual uint32_t getPongResults(std::string id, int n, std::list<RsRttPongResult
|
||||
virtual int tick();
|
||||
virtual int status();
|
||||
|
||||
|
||||
int sendPackets();
|
||||
void sendPingMeasurements();
|
||||
int processIncoming();
|
||||
|
||||
virtual bool recvItem(RsItem *item); // Overloaded from p3FastService.
|
||||
|
||||
int handlePing(RsItem *item);
|
||||
int handlePong(RsItem *item);
|
||||
|
@ -67,6 +67,7 @@ bool p3Service::recvItem(RsItem *item)
|
||||
|
||||
recv_queue.push_back(item);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -91,8 +91,10 @@ bool sockaddr_storage_ipv6_isExternalNet(const struct sockaddr_storage &addr);
|
||||
// so hidding details behind function.
|
||||
int universal_bind(int fd, const struct sockaddr *addr, socklen_t socklen)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "universal_bind()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
const struct sockaddr_storage *ss_addr = (struct sockaddr_storage *) addr;
|
||||
socklen_t len = socklen;
|
||||
@ -132,8 +134,11 @@ void sockaddr_storage_clear(struct sockaddr_storage &addr)
|
||||
// mods.
|
||||
bool sockaddr_storage_zeroip(struct sockaddr_storage &addr)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_zeroip()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
switch(addr.ss_family)
|
||||
{
|
||||
case AF_INET:
|
||||
@ -153,8 +158,11 @@ bool sockaddr_storage_zeroip(struct sockaddr_storage &addr)
|
||||
|
||||
bool sockaddr_storage_copyip(struct sockaddr_storage &dst, const struct sockaddr_storage &src)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_copyip()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
switch(src.ss_family)
|
||||
{
|
||||
case AF_INET:
|
||||
@ -196,8 +204,11 @@ uint16_t sockaddr_storage_port(const struct sockaddr_storage &addr)
|
||||
|
||||
bool sockaddr_storage_setport(struct sockaddr_storage &addr, uint16_t port)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_setport()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
switch(addr.ss_family)
|
||||
{
|
||||
case AF_INET:
|
||||
@ -217,8 +228,10 @@ bool sockaddr_storage_setport(struct sockaddr_storage &addr, uint16_t port)
|
||||
|
||||
bool sockaddr_storage_setipv4(struct sockaddr_storage &addr, const sockaddr_in *addr_ipv4)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_setipv4()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
sockaddr_storage_clear(addr);
|
||||
struct sockaddr_in *ipv4_ptr = to_ipv4_ptr(addr);
|
||||
@ -248,8 +261,10 @@ bool sockaddr_storage_setipv6(struct sockaddr_storage &addr, const sockaddr_in6
|
||||
|
||||
bool sockaddr_storage_ipv4_aton(struct sockaddr_storage &addr, const char *name)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_ipv4_aton()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
struct sockaddr_in *ipv4_ptr = to_ipv4_ptr(addr);
|
||||
ipv4_ptr->sin_family = AF_INET;
|
||||
@ -285,8 +300,10 @@ bool operator<(const struct sockaddr_storage &a, const struct sockaddr_storage &
|
||||
|
||||
bool sockaddr_storage_same(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_same()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
if (!sockaddr_storage_samefamily(addr, addr2))
|
||||
return false;
|
||||
@ -310,16 +327,20 @@ bool sockaddr_storage_same(const struct sockaddr_storage &addr, const struct soc
|
||||
|
||||
bool sockaddr_storage_samefamily(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_samefamily()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
return (addr.ss_family == addr2.ss_family);
|
||||
}
|
||||
|
||||
bool sockaddr_storage_sameip(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_sameip()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
if (!sockaddr_storage_samefamily(addr, addr2))
|
||||
return false;
|
||||
@ -343,8 +364,10 @@ bool sockaddr_storage_sameip(const struct sockaddr_storage &addr, const struct s
|
||||
|
||||
bool sockaddr_storage_samenet(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_samenet()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
if (!sockaddr_storage_samefamily(addr, addr2))
|
||||
return false;
|
||||
@ -367,8 +390,10 @@ bool sockaddr_storage_samenet(const struct sockaddr_storage &addr, const struct
|
||||
|
||||
bool sockaddr_storage_samesubnet(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_samesubnet()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
if (!sockaddr_storage_samefamily(addr, addr2))
|
||||
return false;
|
||||
@ -463,8 +488,10 @@ std::string sockaddr_storage_porttostring(const struct sockaddr_storage &addr)
|
||||
/********************************* Net Checks ***********************************/
|
||||
bool sockaddr_storage_isnull(const struct sockaddr_storage &addr)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_isnull()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
if (addr.ss_family == 0)
|
||||
return true;
|
||||
@ -486,8 +513,10 @@ bool sockaddr_storage_isnull(const struct sockaddr_storage &addr)
|
||||
|
||||
bool sockaddr_storage_isValidNet(const struct sockaddr_storage &addr)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_isValidNet()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
switch(addr.ss_family)
|
||||
{
|
||||
@ -507,8 +536,10 @@ bool sockaddr_storage_isValidNet(const struct sockaddr_storage &addr)
|
||||
|
||||
bool sockaddr_storage_isLoopbackNet(const struct sockaddr_storage &addr)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_isLoopbackNet()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
switch(addr.ss_family)
|
||||
{
|
||||
@ -529,8 +560,10 @@ bool sockaddr_storage_isLoopbackNet(const struct sockaddr_storage &addr)
|
||||
|
||||
bool sockaddr_storage_isPrivateNet(const struct sockaddr_storage &addr)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_isPrivateNet()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
switch(addr.ss_family)
|
||||
{
|
||||
@ -551,8 +584,10 @@ bool sockaddr_storage_isPrivateNet(const struct sockaddr_storage &addr)
|
||||
|
||||
bool sockaddr_storage_isExternalNet(const struct sockaddr_storage &addr)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_isExternalNet()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
switch(addr.ss_family)
|
||||
{
|
||||
@ -608,8 +643,10 @@ const struct sockaddr_in6 *to_const_ipv6_ptr(const struct sockaddr_storage &addr
|
||||
|
||||
bool sockaddr_storage_ipv4_zeroip(struct sockaddr_storage &addr)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_ipv4_zeroip()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
struct sockaddr_in *ipv4_ptr = to_ipv4_ptr(addr);
|
||||
memset(&(ipv4_ptr->sin_addr), 0, sizeof(ipv4_ptr->sin_addr));
|
||||
@ -619,8 +656,10 @@ bool sockaddr_storage_ipv4_zeroip(struct sockaddr_storage &addr)
|
||||
|
||||
bool sockaddr_storage_ipv4_copyip(struct sockaddr_storage &dst, const struct sockaddr_storage &src)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_ipv4_copyip()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
struct sockaddr_in *dst_ptr = to_ipv4_ptr(dst);
|
||||
const struct sockaddr_in *src_ptr = to_const_ipv4_ptr(src);
|
||||
@ -644,8 +683,10 @@ uint16_t sockaddr_storage_ipv4_port(const struct sockaddr_storage &addr)
|
||||
|
||||
bool sockaddr_storage_ipv4_setport(struct sockaddr_storage &addr, uint16_t port)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_ipv4_setport()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
struct sockaddr_in *ipv4_ptr = to_ipv4_ptr(addr);
|
||||
ipv4_ptr->sin_port = htons(port);
|
||||
@ -700,8 +741,10 @@ bool sockaddr_storage_ipv6_setport(struct sockaddr_storage &addr, uint16_t port)
|
||||
|
||||
bool sockaddr_storage_ipv4_lessthan(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_ipv4_lessthan()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
const struct sockaddr_in *ptr1 = to_const_ipv4_ptr(addr);
|
||||
const struct sockaddr_in *ptr2 = to_const_ipv4_ptr(addr2);
|
||||
@ -715,8 +758,10 @@ bool sockaddr_storage_ipv4_lessthan(const struct sockaddr_storage &addr, const s
|
||||
|
||||
bool sockaddr_storage_ipv4_same(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_ipv4_same()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
const struct sockaddr_in *ptr1 = to_const_ipv4_ptr(addr);
|
||||
const struct sockaddr_in *ptr2 = to_const_ipv4_ptr(addr2);
|
||||
@ -727,8 +772,10 @@ bool sockaddr_storage_ipv4_same(const struct sockaddr_storage &addr, const struc
|
||||
|
||||
bool sockaddr_storage_ipv4_sameip(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_ipv4_sameip()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
const struct sockaddr_in *ptr1 = to_const_ipv4_ptr(addr);
|
||||
const struct sockaddr_in *ptr2 = to_const_ipv4_ptr(addr2);
|
||||
@ -742,8 +789,10 @@ bool sockaddr_storage_ipv4_samenet(const struct sockaddr_storage &addr, const st
|
||||
(void) addr;
|
||||
(void) addr2;
|
||||
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_ipv4_samenet()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
const struct sockaddr_in *ptr1 = to_const_ipv4_ptr(addr);
|
||||
@ -756,8 +805,10 @@ bool sockaddr_storage_ipv4_samesubnet(const struct sockaddr_storage &addr, const
|
||||
(void) addr;
|
||||
(void) addr2;
|
||||
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_ipv4_samesubnet() using pqinetwork::isSameSubnet()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
const struct sockaddr_in *ptr1 = to_const_ipv4_ptr(addr);
|
||||
const struct sockaddr_in *ptr2 = to_const_ipv4_ptr(addr2);
|
||||
@ -866,8 +917,10 @@ std::string sockaddr_storage_ipv6_iptostring(const struct sockaddr_storage & /*
|
||||
/********************************* Net Checks ***********************************/
|
||||
bool sockaddr_storage_ipv4_isnull(const struct sockaddr_storage &addr)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_ipv4_isnull()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
const struct sockaddr_in *ptr1 = to_const_ipv4_ptr(addr);
|
||||
if (ptr1->sin_family != AF_INET)
|
||||
@ -883,8 +936,10 @@ bool sockaddr_storage_ipv4_isnull(const struct sockaddr_storage &addr)
|
||||
|
||||
bool sockaddr_storage_ipv4_isValidNet(const struct sockaddr_storage &addr)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_ipv4_isValidNet()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
const struct sockaddr_in *ptr1 = to_const_ipv4_ptr(addr);
|
||||
if (ptr1->sin_family != AF_INET)
|
||||
@ -897,8 +952,10 @@ bool sockaddr_storage_ipv4_isValidNet(const struct sockaddr_storage &addr)
|
||||
|
||||
bool sockaddr_storage_ipv4_isLoopbackNet(const struct sockaddr_storage &addr)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_ipv4_isLoopbackNet()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
const struct sockaddr_in *ptr1 = to_const_ipv4_ptr(addr);
|
||||
@ -911,8 +968,10 @@ bool sockaddr_storage_ipv4_isLoopbackNet(const struct sockaddr_storage &addr)
|
||||
|
||||
bool sockaddr_storage_ipv4_isPrivateNet(const struct sockaddr_storage &addr)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_ipv4_isPrivateNet()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
const struct sockaddr_in *ptr1 = to_const_ipv4_ptr(addr);
|
||||
@ -925,8 +984,10 @@ bool sockaddr_storage_ipv4_isPrivateNet(const struct sockaddr_storage &addr)
|
||||
|
||||
bool sockaddr_storage_ipv4_isExternalNet(const struct sockaddr_storage &addr)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_ipv4_isExternalNet()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
const struct sockaddr_in *ptr1 = to_const_ipv4_ptr(addr);
|
||||
if (ptr1->sin_family != AF_INET)
|
||||
|
Loading…
Reference in New Issue
Block a user