Added Rate Cap to RateInterface, and enabled it for Relay Connections.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-dhtmods@4768 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2012-01-08 18:40:09 +00:00
parent abbebf48ff
commit dc8e596c0f
3 changed files with 62 additions and 1 deletions

View File

@ -58,7 +58,9 @@ class RateInterface
public:
RateInterface()
:bw_in(0), bw_out(0), bwMax_in(0), bwMax_out(0) { return; }
:bw_in(0), bw_out(0), bwMax_in(0), bwMax_out(0),
bwCapEnabled(false), bwCap_in(0), bwCap_out(0) { return; }
virtual ~RateInterface() { return; }
virtual float getRate(bool in)
@ -78,12 +80,50 @@ virtual float getMaxRate(bool in)
virtual void setMaxRate(bool in, float val)
{
if (in)
{
bwMax_in = val;
if (bwCapEnabled)
{
if (bwMax_in > bwCap_in)
{
bwMax_in = bwCap_in;
}
}
}
else
{
bwMax_out = val;
if (bwCapEnabled)
{
if (bwMax_out > bwCap_out)
{
bwMax_out = bwCap_out;
}
}
}
return;
}
virtual void setRateCap(float val_in, float val_out)
{
if ((val_in == 0) && (val_out == 0))
{
std::cerr << "RateInterface::setRateCap() Now disabled" << std::endl;
bwCapEnabled = false;
}
else
{
std::cerr << "RateInterface::setRateCap() Enabled ";
std::cerr << "in: " << bwCap_in << " out: " << bwCap_out" << std::endl;
bwCapEnabled = true;
bwCap_in = val_in;
bwCap_out = val_out;
}
return;
}
protected:
void setRate(bool in, float val)
@ -97,6 +137,9 @@ void setRate(bool in, float val)
private:
float bw_in, bw_out, bwMax_in, bwMax_out;
bool bwCapEnabled;
float bwCap_in, bwCap_out;
};

View File

@ -431,6 +431,9 @@ int pqiperson::connect(uint32_t type, struct sockaddr_in raddr,
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::connect reset() before connection attempt");
(it->second)->reset();
std::cerr << "pqiperson::connect() WARNING, clearing rate cap" << std::endl;
setRateCap(0,0);
#ifdef PERSON_DEBUG
std::cerr << "pqiperson::connect() setting connect_parameters" << std::endl;
#endif
@ -489,3 +492,17 @@ void pqiperson::setMaxRate(bool in, float val)
}
}
void pqiperson::setRateCap(float val_in, float val_out)
{
// set to all of them. (and us)
PQInterface::setRateCap(val_in, val_out);
// clean up the children.
std::map<uint32_t, pqiconnect *>::iterator it;
for(it = kids.begin(); it != kids.end(); it++)
{
(it->second) -> setRateCap(val_in, val_out);
}
}

View File

@ -251,6 +251,7 @@ int pqissludp::Initiate_Connection()
std::cerr << remote_addr << ")" << std::endl;
tou_connect_via_relay(sockfd, &(mConnectSrcAddr), &(mConnectProxyAddr), &(remote_addr));
parent()->setRateCap( mConnectBandwidth / 1000.0, mConnectBandwidth / 1000.0); // Set RateCap.
}
if (0 != err)