diff --git a/libretroshare/src/pqi/pqi_base.h b/libretroshare/src/pqi/pqi_base.h index 275a6d058..94d1fc96e 100644 --- a/libretroshare/src/pqi/pqi_base.h +++ b/libretroshare/src/pqi/pqi_base.h @@ -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; + }; diff --git a/libretroshare/src/pqi/pqiperson.cc b/libretroshare/src/pqi/pqiperson.cc index 5a6c519e4..9aa5889d7 100644 --- a/libretroshare/src/pqi/pqiperson.cc +++ b/libretroshare/src/pqi/pqiperson.cc @@ -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::iterator it; + for(it = kids.begin(); it != kids.end(); it++) + { + (it->second) -> setRateCap(val_in, val_out); + } +} + + + diff --git a/libretroshare/src/pqi/pqissludp.cc b/libretroshare/src/pqi/pqissludp.cc index 0987f09d9..6c1263859 100644 --- a/libretroshare/src/pqi/pqissludp.cc +++ b/libretroshare/src/pqi/pqissludp.cc @@ -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)