diff --git a/libretroshare/src/pqi/pqihandler.cc b/libretroshare/src/pqi/pqihandler.cc index 8fdb5fe81..882a1b773 100644 --- a/libretroshare/src/pqi/pqihandler.cc +++ b/libretroshare/src/pqi/pqihandler.cc @@ -30,6 +30,7 @@ #include #include "util/rsdebug.h" +#include const int pqihandlerzone = 34283; /**** @@ -553,184 +554,99 @@ int pqihandler::UpdateRates() float avail_in = getMaxRate(true); float avail_out = getMaxRate(false); - float avg_rate_in = avail_in/num_sm; - float avg_rate_out = avail_out/num_sm; - - float indiv_in = getMaxIndivRate(true); - float indiv_out = getMaxIndivRate(false); - float used_bw_in = 0; float used_bw_out = 0; - float extra_bw_in = 0; - float extra_bw_out = 0; - - int maxxed_in = 0; - int maxxed_out = 0; - /* Lock once rates have been retrieved */ RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/ - // loop through modules.... + int effectiveUploadsSm = 0; + int effectiveDownloadsSm = 0; + // loop through modules to get the used bandwith and the number of modules that are affectively transfering + //std::cerr << " Looping through modules" << std::endl; for(it = mods.begin(); it != mods.end(); it++) { SearchModule *mod = (it -> second); float crate_in = mod -> pqi -> getRate(true); + if (crate_in > 0.01 * avail_in || crate_in > 0.1) + { + effectiveDownloadsSm ++; + } + float crate_out = mod -> pqi -> getRate(false); + if (crate_out > 0.01 * avail_out || crate_out > 0.1) + { + effectiveUploadsSm ++; + } used_bw_in += crate_in; used_bw_out += crate_out; - - if (crate_in > avg_rate_in) - { - if (mod -> pqi -> getMaxRate(true) == indiv_in) - { - maxxed_in++; - } - extra_bw_in += crate_in - avg_rate_in; - } - if (crate_out > avg_rate_out) - { - if (mod -> pqi -> getMaxRate(false) == indiv_out) - { - maxxed_out++; - } - extra_bw_out += crate_out - avg_rate_out; - } - //std::cerr << "\tSM(" << mod -> smi << ")"; - //std::cerr << "In A: " << mod -> pqi -> getMaxRate(true); - //std::cerr << " C: " << crate_in; - //std::cerr << " && Out A: " << mod -> pqi -> getMaxRate(false); - //std::cerr << " C: " << crate_out << std::endl; } - //std::cerr << "Totals (In) Used B/W " << used_bw_in; - //std::cerr << " Excess B/W " << extra_bw_in; - //std::cerr << " Available B/W " << avail_in << std::endl; - //std::cerr << "Totals (Out) Used B/W " << used_bw_out; - //std::cerr << " Excess B/W " << extra_bw_out; - //std::cerr << " Available B/W " << avail_out << std::endl; +// std::cerr << "Totals (In) Used B/W " << used_bw_in; +// std::cerr << " Available B/W " << avail_in; +// std::cerr << " Effective transfers " << effectiveDownloadsSm << std::endl; +// std::cerr << "Totals (Out) Used B/W " << used_bw_out; +// std::cerr << " Available B/W " << avail_out; +// std::cerr << " Effective transfers " << effectiveUploadsSm << std::endl; locked_StoreCurrentRates(used_bw_in, used_bw_out); - if (used_bw_in > avail_in) - { - //std::cerr << "Decreasing Incoming B/W!" << std::endl; - - // drop all above the avg down! - float fchg = (used_bw_in - avail_in) / (float) extra_bw_in; - for(it = mods.begin(); it != mods.end(); it++) - { - SearchModule *mod = (it -> second); - float crate_in = mod -> pqi -> getRate(true); - float new_max = avg_rate_in; - if (crate_in > avg_rate_in) - { - new_max = avg_rate_in + (1 - fchg) * - (crate_in - avg_rate_in); - } - if (new_max > indiv_in) - { - new_max = indiv_in; - } - mod -> pqi -> setMaxRate(true, new_max); - } + //computing average rates for effective transfers + float max_in_effective = avail_in / num_sm; + if (effectiveDownloadsSm != 0) { + max_in_effective = avail_in / effectiveDownloadsSm; } - // if not maxxed already and using less than 95% - else if ((maxxed_in != num_sm) && (used_bw_in < 0.95 * avail_in)) - { - //std::cerr << "Increasing Incoming B/W!" << std::endl; - - // increase. - float fchg = (avail_in - used_bw_in) / avail_in; - for(it = mods.begin(); it != mods.end(); it++) - { - SearchModule *mod = (it -> second); - float crate_in = mod -> pqi -> getRate(true); - float max_in = mod -> pqi -> getMaxRate(true); - - if (max_in == indiv_in) - { - // do nothing... - } - else - { - float new_max = max_in; - if (max_in < avg_rate_in) - { - new_max = avg_rate_in * (1 + fchg); - } - else if (crate_in > 0.5 * max_in) - { - new_max = max_in * (1 + fchg); - } - if (new_max > indiv_in) - { - new_max = indiv_in; - } - mod -> pqi -> setMaxRate(true, new_max); - } - } - + float max_out_effective = avail_out / num_sm; + if (effectiveUploadsSm != 0) { + max_out_effective = avail_out / effectiveUploadsSm; } - - if (used_bw_out > avail_out) - { - //std::cerr << "Decreasing Outgoing B/W!" << std::endl; - // drop all above the avg down! - float fchg = (used_bw_out - avail_out) / (float) extra_bw_out; - for(it = mods.begin(); it != mods.end(); it++) - { - SearchModule *mod = (it -> second); - float crate_out = mod -> pqi -> getRate(false); - float new_max = avg_rate_out; - if (crate_out > avg_rate_out) - { - new_max = avg_rate_out + (1 - fchg) * - (crate_out - avg_rate_out); - } - if (new_max > indiv_out) - { - new_max = indiv_out; - } - mod -> pqi -> setMaxRate(false, new_max); - } + //modify the outgoing rates if bandwith is not used well + float rate_out_modifier = 0; + if (used_bw_out / avail_out < 0.95) { + rate_out_modifier = 0.001 * avail_out; + } else if (used_bw_out / avail_out > 1.05) { + rate_out_modifier = - 0.001 * avail_out; } - // if not maxxed already and using less than 95% - else if ((maxxed_out != num_sm) && (used_bw_out < 0.95 * avail_out)) + if (rate_out_modifier != 0) { + for(it = mods.begin(); it != mods.end(); it++) + { + SearchModule *mod = (it -> second); + mod -> pqi -> setMaxRate(false, mod -> pqi -> getMaxRate(false) + rate_out_modifier); + } + } + + //modify the incoming rates if bandwith is not used well + float rate_in_modifier = 0; + if (used_bw_in / avail_in < 0.95) { + rate_in_modifier = 0.001 * avail_in; + } else if (used_bw_in / avail_in > 1.05) { + rate_in_modifier = - 0.001 * avail_in; + } + if (rate_in_modifier != 0) { + for(it = mods.begin(); it != mods.end(); it++) + { + SearchModule *mod = (it -> second); + mod -> pqi -> setMaxRate(true, mod -> pqi -> getMaxRate(true) + rate_in_modifier); + } + } + + //cap the rates + for(it = mods.begin(); it != mods.end(); it++) { - //std::cerr << "Increasing Outgoing B/W!" << std::endl; - // increase. - float fchg = (avail_out - used_bw_out) / avail_out; - for(it = mods.begin(); it != mods.end(); it++) - { - SearchModule *mod = (it -> second); - float crate_out = mod -> pqi -> getRate(false); - float max_out = mod -> pqi -> getMaxRate(false); - - if (max_out == indiv_out) - { - // do nothing... - } - else - { - float new_max = max_out; - if (max_out < avg_rate_out) - { - new_max = avg_rate_out * (1 + fchg); - } - else if (crate_out > 0.5 * max_out) - { - new_max = max_out * (1 + fchg); - } - if (new_max > indiv_out) - { - new_max = indiv_out; - } - mod -> pqi -> setMaxRate(false, new_max); - } + SearchModule *mod = (it -> second); + if (mod -> pqi -> getMaxRate(false) < max_out_effective) { + mod -> pqi -> setMaxRate(false, max_out_effective); + } + if (mod -> pqi -> getMaxRate(false) > avail_out) { + mod -> pqi -> setMaxRate(false, avail_out); + } + if (mod -> pqi -> getMaxRate(true) < max_in_effective) { + mod -> pqi -> setMaxRate(true, max_in_effective); + } + if (mod -> pqi -> getMaxRate(true) > avail_in) { + mod -> pqi -> setMaxRate(true, avail_in); } - } return 1; diff --git a/libretroshare/src/pqi/pqihandler.h b/libretroshare/src/pqi/pqihandler.h index 169c7520f..dc3c85310 100644 --- a/libretroshare/src/pqi/pqihandler.h +++ b/libretroshare/src/pqi/pqihandler.h @@ -75,8 +75,9 @@ virtual int SendRsRawItem(RsRawItem *); virtual RsRawItem *GetRsRawItem(); // rate control. -void setMaxIndivRate(bool in, float val); -float getMaxIndivRate(bool in); +//indiv rate is deprecated +//void setMaxIndivRate(bool in, float val); +//float getMaxIndivRate(bool in); void setMaxRate(bool in, float val); float getMaxRate(bool in); @@ -118,24 +119,24 @@ void locked_StoreCurrentRates(float in, float out); float rateTotal_out; }; -inline void pqihandler::setMaxIndivRate(bool in, float val) -{ - RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/ - if (in) - rateIndiv_in = val; - else - rateIndiv_out = val; - return; -} - -inline float pqihandler::getMaxIndivRate(bool in) -{ - RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/ - if (in) - return rateIndiv_in; - else - return rateIndiv_out; -} +//inline void pqihandler::setMaxIndivRate(bool in, float val) +//{ +// RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/ +// if (in) +// rateIndiv_in = val; +// else +// rateIndiv_out = val; +// return; +//} +// +//inline float pqihandler::getMaxIndivRate(bool in) +//{ +// RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/ +// if (in) +// return rateIndiv_in; +// else +// return rateIndiv_out; +//} inline void pqihandler::setMaxRate(bool in, float val) { diff --git a/libretroshare/src/pqi/pqipersongrp.cc b/libretroshare/src/pqi/pqipersongrp.cc index 115a41515..4a78a0358 100644 --- a/libretroshare/src/pqi/pqipersongrp.cc +++ b/libretroshare/src/pqi/pqipersongrp.cc @@ -223,8 +223,7 @@ static const std::string pqih_ftr("PQIH_FTR"); int pqipersongrp::save_config() { char line[512]; - sprintf(line, "%f %f %f %f", getMaxRate(true), getMaxRate(false), - getMaxIndivRate(true), getMaxIndivRate(false)); + sprintf(line, "%f %f", getMaxRate(true), getMaxRate(false)); if (config) { config -> setSetting(pqih_ftr, std::string(line)); @@ -240,14 +239,12 @@ int pqipersongrp::load_config() line = config -> getSetting(pqih_ftr); } - float mri, mro, miri, miro; - - if (4 == sscanf(line.c_str(), "%f %f %f %f", &mri, &mro, &miri, &miro)) + float mri, mro; + + if (2 == sscanf(line.c_str(), "%f %f", &mri, &mro)) { setMaxRate(true, mri); setMaxRate(false, mro); - setMaxIndivRate(true, miri); - setMaxIndivRate(false, miro); } else { @@ -256,8 +253,6 @@ int pqipersongrp::load_config() setMaxRate(true, 500.0); setMaxRate(false, 500.0); - setMaxIndivRate(true, 100.0); - setMaxIndivRate(false, 100.0); } return 1; diff --git a/libretroshare/src/rsiface/rsiface.h b/libretroshare/src/rsiface/rsiface.h index 1dc8326bb..87ae61979 100644 --- a/libretroshare/src/rsiface/rsiface.h +++ b/libretroshare/src/rsiface/rsiface.h @@ -171,7 +171,7 @@ class RsControl /* The Main Interface Class - for controlling the server */ /****************************************/ /* Config */ - virtual int ConfigSetDataRates( int total, int indiv ) = 0; + virtual int ConfigSetDataRates( int totalDownload, int totalUpload ) = 0; virtual int ConfigGetDataRates( float &inKb, float &outKb) = 0; virtual int ConfigSetBootPrompt( bool on ) = 0; virtual void ConfigFinalSave( ) = 0; diff --git a/libretroshare/src/rsiface/rstypes.h b/libretroshare/src/rsiface/rstypes.h index c6ef19d2b..7e4458dfb 100644 --- a/libretroshare/src/rsiface/rstypes.h +++ b/libretroshare/src/rsiface/rstypes.h @@ -126,7 +126,8 @@ class RsConfig bool firewalled; bool forwardPort; - int maxDataRate; /* kb */ + int maxDownloadDataRate; /* kb */ + int maxUploadDataRate; /* kb */ int maxIndivDataRate; /* kb */ int promptAtBoot; /* popup the password prompt */ diff --git a/libretroshare/src/rsserver/p3face-config.cc b/libretroshare/src/rsserver/p3face-config.cc index 3f15cbd1d..16dcca0fb 100644 --- a/libretroshare/src/rsserver/p3face-config.cc +++ b/libretroshare/src/rsserver/p3face-config.cc @@ -41,7 +41,7 @@ const int p3facemsgzone = 11453; /* RsIface Config */ /* Config */ -int RsServer::ConfigSetDataRates( int total, int indiv ) /* in kbrates */ +int RsServer::ConfigSetDataRates( int totalDownload, int totalUpload ) /* in kbrates */ { /* fill the rsiface class */ RsIface &iface = getIface(); @@ -50,10 +50,8 @@ int RsServer::ConfigSetDataRates( int total, int indiv ) /* in kbrates */ lockRsCore(); /* LOCK */ iface.lockData(); /* LOCK */ - pqih -> setMaxRate(true, total); - pqih -> setMaxRate(false, total); - pqih -> setMaxIndivRate(true, indiv); - pqih -> setMaxIndivRate(false, indiv); + pqih -> setMaxRate(true, totalDownload); + pqih -> setMaxRate(false, totalUpload); pqih -> save_config(); @@ -120,8 +118,9 @@ int RsServer::UpdateAllConfig() config.extPort = ntohs(pstate.serveraddr.sin_port); /* data rates */ - config.maxDataRate = (int) pqih -> getMaxRate(true); /* kb */ - config.maxIndivDataRate = (int) pqih -> getMaxIndivRate(true);/* kb */ + config.maxDownloadDataRate = (int) pqih -> getMaxRate(true); /* kb */ + config.maxUploadDataRate = (int) pqih -> getMaxRate(false); /* kb */ + config.promptAtBoot = true; /* popup the password prompt */ /* update network configuration */ diff --git a/libretroshare/src/rsserver/p3face.h b/libretroshare/src/rsserver/p3face.h index b8e7a53d1..d17665a42 100644 --- a/libretroshare/src/rsserver/p3face.h +++ b/libretroshare/src/rsserver/p3face.h @@ -137,7 +137,7 @@ class RsServer: public RsControl, public RsThread /* Config */ virtual int ConfigGetDataRates(float &inKb, float &outKb); - virtual int ConfigSetDataRates( int total, int indiv ); + virtual int ConfigSetDataRates( int totalDownload, int totalUpload ); virtual int ConfigSetBootPrompt( bool on ); virtual void ConfigFinalSave( ); diff --git a/retroshare-gui/src/gui/PeersDialog.cpp b/retroshare-gui/src/gui/PeersDialog.cpp index b39895e8b..538994654 100644 --- a/retroshare-gui/src/gui/PeersDialog.cpp +++ b/retroshare-gui/src/gui/PeersDialog.cpp @@ -654,7 +654,9 @@ void PeersDialog::insertChat() { if (!rsMsgs->chatAvailable()) { -// std::cerr << "no chat available." << std::endl ; +#ifdef PEERS_DEBUG + std::cerr << "no chat available." << std::endl ; +#endif return; } diff --git a/retroshare-gui/src/gui/Preferences/ServerDialog.cpp b/retroshare-gui/src/gui/Preferences/ServerDialog.cpp index 396474fe7..47459ef5e 100644 --- a/retroshare-gui/src/gui/Preferences/ServerDialog.cpp +++ b/retroshare-gui/src/gui/Preferences/ServerDialog.cpp @@ -91,12 +91,6 @@ ServerDialog::save(QString &errmsg) } -/** Change of maxDataRate limits the Individual Data Rate */ -void ServerDialog::setMaximumIndivRate(int maximum) { - ui.indivRate->setMaximum(maximum); -} - - /** Loads the settings for this page */ void ServerDialog::load() { @@ -142,15 +136,8 @@ void ServerDialog::load() rsiface->lockData(); /* Lock Interface */ - ui.totalRate->setValue(rsiface->getConfig().maxDataRate); - ui.indivRate->setValue(rsiface->getConfig().maxIndivDataRate); - - // It makes no sense to set the total transfer rate lower than the individual rate. - // Avoid this by setting the upper limit for individual rate to total transfer rate now, - // and every time the user changes the total transfer rate. - ui.indivRate->setMaximum(rsiface->getConfig().maxDataRate); - QObject::connect(ui.totalRate, SIGNAL (valueChanged(int)), - this, SLOT (setMaximumIndivRate(int))); + ui.totalDownloadRate->setValue(rsiface->getConfig().maxDownloadDataRate); + ui.totalUploadRate->setValue(rsiface->getConfig().maxUploadDataRate); rsiface->unlockData(); /* UnLock Interface */ @@ -371,7 +358,7 @@ void ServerDialog::saveAddresses() rsPeers->setExtAddress(rsPeers->getOwnId(), ui.extAddress->text().toStdString(), ui.extPort->value()); } - rsicontrol->ConfigSetDataRates( ui.totalRate->value(), ui.indivRate->value() ); + rsicontrol->ConfigSetDataRates( ui.totalDownloadRate->value(), ui.totalUploadRate->value() ); load(); } diff --git a/retroshare-gui/src/gui/Preferences/ServerDialog.h b/retroshare-gui/src/gui/Preferences/ServerDialog.h index 0723d5b05..185965192 100644 --- a/retroshare-gui/src/gui/Preferences/ServerDialog.h +++ b/retroshare-gui/src/gui/Preferences/ServerDialog.h @@ -50,7 +50,6 @@ private slots: void saveAddresses(); void toggleUPnP(); void toggleIpDetermination(bool) ; - void setMaximumIndivRate(int); private: /** A RshareSettings object used for saving/loading settings */ diff --git a/retroshare-gui/src/gui/Preferences/ServerDialog.ui b/retroshare-gui/src/gui/Preferences/ServerDialog.ui index e2792b34c..92b7adf7b 100644 --- a/retroshare-gui/src/gui/Preferences/ServerDialog.ui +++ b/retroshare-gui/src/gui/Preferences/ServerDialog.ui @@ -1,170 +1,171 @@ - + + ServerDialog - - + + 0 0 - 405 - 357 + 467 + 448 - - + + 0 0 - + - - - + + + 0 0 0 - - - + + + 208 208 208 - - - + + + 255 255 255 - - - + + + 247 247 247 - - - + + + 104 104 104 - - - + + + 139 139 139 - - - + + + 0 0 0 - - - + + + 255 255 255 - - - + + + 0 0 0 - - - + + + 255 255 255 - - - + + + 240 240 240 - - - + + + 0 0 0 - - - + + + 0 0 128 - - - + + + 255 255 255 - - - + + + 0 0 255 - - - + + + 255 0 255 - - - + + + 231 231 231 @@ -173,153 +174,153 @@ - - - + + + 0 0 0 - - - + + + 208 208 208 - - - + + + 255 255 255 - - - + + + 247 247 247 - - - + + + 104 104 104 - - - + + + 139 139 139 - - - + + + 0 0 0 - - - + + + 255 255 255 - - - + + + 0 0 0 - - - + + + 255 255 255 - - - + + + 240 240 240 - - - + + + 0 0 0 - - - + + + 192 192 192 - - - + + + 0 0 0 - - - + + + 0 0 255 - - - + + + 255 0 255 - - - + + + 231 231 231 @@ -328,153 +329,153 @@ - - - + + + 104 104 104 - - - + + + 208 208 208 - - - + + + 255 255 255 - - - + + + 247 247 247 - - - + + + 104 104 104 - - - + + + 139 139 139 - - - + + + 104 104 104 - - - + + + 255 255 255 - - - + + + 104 104 104 - - - + + + 240 240 240 - - - + + + 240 240 240 - - - + + + 0 0 0 - - - + + + 0 0 128 - - - + + + 255 255 255 - - - + + + 0 0 255 - - - + + + 255 0 255 - - - + + + 231 231 231 @@ -484,86 +485,74 @@ - + Qt::NoContextMenu - - + + 6 - - 6 - - - 6 - - - 6 - - + 0 - - 0 - - - - - + + + + 0 0 - + Network Configuration (takes effect after restart) - + - + - + - + Automatic - + Firewalled - + Forwarded Port - + - + - + DHT Enabled - + DHT Disabled - + - + Discovery Enabled - + Discovery Disabled @@ -575,10 +564,10 @@ - + Qt::Horizontal - + 40 20 @@ -589,42 +578,42 @@ - - - + + + 0 - - + + Network Configuration - - - - - + + + + + 0 0 - + Network Configuration - + - + - + - - + + Local Address - - + + External Address @@ -632,49 +621,49 @@ - - - + + + - - - + + + Port: - - - + + + 0 - + 65535 - + 7812 - - + + - - - + + + Port: - - - + + + 0 - + 65535 - + 7812 @@ -683,54 +672,41 @@ - - - - Qt::Vertical - - - - 20 - 40 - - - - - - + + IP Service - - - - + + + + IP check service - - - - + + + + If you unckeck this, RetroShare can only determine your IP when you connect to somebody. Leaving this checked helps connecting when you have few friends. It also helps if you're behind a firewall or a VPN. - + Allow RetroShare to ask my ip to these websites: - + false - - - + + + QAbstractItemView::NoEditTriggers @@ -742,51 +718,42 @@ behind a firewall or a VPN. - - - - + + + + 0 0 - + Transfer Rates - + - - + + 6 - - 0 - - - 0 - - - 0 - - + 0 - - - Total Rate (KB/s) + + + Download (KB/s) - - + + 1 - + 12500 - + 1 @@ -794,57 +761,32 @@ behind a firewall or a VPN. - - + + 6 - - 0 - - - 0 - - - 0 - - - 0 - - - - Per Person + + + Upload (KB/s) - - + + 1 - + 12500 - + 1 - - - - Qt::Horizontal - - - - 40 - 20 - - - - @@ -854,11 +796,8 @@ behind a firewall or a VPN. localAddress localPort extPort - totalRate - indivRate + totalDownloadRate - - - + diff --git a/retroshare-gui/src/rsiface/rsiface.h b/retroshare-gui/src/rsiface/rsiface.h index 1dc8326bb..87ae61979 100644 --- a/retroshare-gui/src/rsiface/rsiface.h +++ b/retroshare-gui/src/rsiface/rsiface.h @@ -171,7 +171,7 @@ class RsControl /* The Main Interface Class - for controlling the server */ /****************************************/ /* Config */ - virtual int ConfigSetDataRates( int total, int indiv ) = 0; + virtual int ConfigSetDataRates( int totalDownload, int totalUpload ) = 0; virtual int ConfigGetDataRates( float &inKb, float &outKb) = 0; virtual int ConfigSetBootPrompt( bool on ) = 0; virtual void ConfigFinalSave( ) = 0; diff --git a/retroshare-gui/src/rsiface/rstypes.h b/retroshare-gui/src/rsiface/rstypes.h index c6ef19d2b..8245fb232 100644 --- a/retroshare-gui/src/rsiface/rstypes.h +++ b/retroshare-gui/src/rsiface/rstypes.h @@ -126,8 +126,8 @@ class RsConfig bool firewalled; bool forwardPort; - int maxDataRate; /* kb */ - int maxIndivDataRate; /* kb */ + int maxDownloadDataRate; /* kb */ + int maxUploadDataRate; /* kb */ int promptAtBoot; /* popup the password prompt */