mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-15 10:00:51 -04:00
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:
parent
abbebf48ff
commit
dc8e596c0f
3 changed files with 62 additions and 1 deletions
|
@ -58,7 +58,9 @@ class RateInterface
|
||||||
public:
|
public:
|
||||||
|
|
||||||
RateInterface()
|
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 ~RateInterface() { return; }
|
||||||
|
|
||||||
virtual float getRate(bool in)
|
virtual float getRate(bool in)
|
||||||
|
@ -78,12 +80,50 @@ virtual float getMaxRate(bool in)
|
||||||
virtual void setMaxRate(bool in, float val)
|
virtual void setMaxRate(bool in, float val)
|
||||||
{
|
{
|
||||||
if (in)
|
if (in)
|
||||||
|
{
|
||||||
bwMax_in = val;
|
bwMax_in = val;
|
||||||
|
if (bwCapEnabled)
|
||||||
|
{
|
||||||
|
if (bwMax_in > bwCap_in)
|
||||||
|
{
|
||||||
|
bwMax_in = bwCap_in;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
bwMax_out = val;
|
bwMax_out = val;
|
||||||
|
if (bwCapEnabled)
|
||||||
|
{
|
||||||
|
if (bwMax_out > bwCap_out)
|
||||||
|
{
|
||||||
|
bwMax_out = bwCap_out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
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:
|
protected:
|
||||||
|
|
||||||
void setRate(bool in, float val)
|
void setRate(bool in, float val)
|
||||||
|
@ -97,6 +137,9 @@ void setRate(bool in, float val)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float bw_in, bw_out, bwMax_in, bwMax_out;
|
float bw_in, bw_out, bwMax_in, bwMax_out;
|
||||||
|
bool bwCapEnabled;
|
||||||
|
float bwCap_in, bwCap_out;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -431,6 +431,9 @@ int pqiperson::connect(uint32_t type, struct sockaddr_in raddr,
|
||||||
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::connect reset() before connection attempt");
|
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::connect reset() before connection attempt");
|
||||||
(it->second)->reset();
|
(it->second)->reset();
|
||||||
|
|
||||||
|
std::cerr << "pqiperson::connect() WARNING, clearing rate cap" << std::endl;
|
||||||
|
setRateCap(0,0);
|
||||||
|
|
||||||
#ifdef PERSON_DEBUG
|
#ifdef PERSON_DEBUG
|
||||||
std::cerr << "pqiperson::connect() setting connect_parameters" << std::endl;
|
std::cerr << "pqiperson::connect() setting connect_parameters" << std::endl;
|
||||||
#endif
|
#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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -251,6 +251,7 @@ int pqissludp::Initiate_Connection()
|
||||||
std::cerr << remote_addr << ")" << std::endl;
|
std::cerr << remote_addr << ")" << std::endl;
|
||||||
|
|
||||||
tou_connect_via_relay(sockfd, &(mConnectSrcAddr), &(mConnectProxyAddr), &(remote_addr));
|
tou_connect_via_relay(sockfd, &(mConnectSrcAddr), &(mConnectProxyAddr), &(remote_addr));
|
||||||
|
parent()->setRateCap( mConnectBandwidth / 1000.0, mConnectBandwidth / 1000.0); // Set RateCap.
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 != err)
|
if (0 != err)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue