diff --git a/libretroshare/src/retroshare/rsturtle.h b/libretroshare/src/retroshare/rsturtle.h index cf8ec76b5..5e324ae5e 100644 --- a/libretroshare/src/retroshare/rsturtle.h +++ b/libretroshare/src/retroshare/rsturtle.h @@ -125,6 +125,9 @@ class RsTurtle // Convenience function. virtual bool isTurtlePeer(const std::string& peer_id) const = 0 ; + // Hardcore handles + virtual void setMaxTRForwardRate(int max_tr_up_rate) = 0 ; + virtual int getMaxTRForwardRate() const = 0 ; protected: FileSharingStrategy _sharing_strategy ; }; diff --git a/libretroshare/src/turtle/p3turtle.cc b/libretroshare/src/turtle/p3turtle.cc index 1df738a29..cfe32affe 100644 --- a/libretroshare/src/turtle/p3turtle.cc +++ b/libretroshare/src/turtle/p3turtle.cc @@ -89,6 +89,8 @@ static const uint32_t MAX_ALLOWED_SR_IN_CACHE = 120 ; /// maximum number of s static const float depth_peer_probability[7] = { 1.0f,0.99f,0.9f,0.7f,0.4f,0.15f,0.1f } ; static const int TUNNEL_REQUEST_PACKET_SIZE = 50 ; static const int MAX_TR_FORWARD_PER_SEC = 20 ; +static const int MAX_TR_FORWARD_PER_SEC_UPPER_LIMIT = 100 ; +static const int MAX_TR_FORWARD_PER_SEC_LOWER_LIMIT = 10 ; static const int DISTANCE_SQUEEZING_POWER = 8 ; p3turtle::p3turtle(p3LinkMgr *lm,ftServer *fs) @@ -110,6 +112,7 @@ p3turtle::p3turtle(p3LinkMgr *lm,ftServer *fs) _traffic_info.reset() ; _sharing_strategy = SHARE_ENTIRE_NETWORK ; + _max_tr_up_rate = MAX_TR_FORWARD_PER_SEC ; } int p3turtle::tick() @@ -552,66 +555,83 @@ RsSerialiser *p3turtle::setupSerialiser() { RsSerialiser *rss = new RsSerialiser ; rss->addSerialType(new RsTurtleSerialiser) ; + rss->addSerialType(new RsGeneralConfigSerialiser()); return rss ; } -bool p3turtle::saveList(bool& cleanup, std::list&) +bool p3turtle::saveList(bool& cleanup, std::list& lst) { #ifdef P3TURTLE_DEBUG std::cerr << "p3turtle: saving list..." << std::endl ; #endif cleanup = true ; - ; -#ifdef TO_REMOVE - RsTurtleSearchResultItem *item = new RsTurtleSearchResultItem ; - item->PeerId("") ; - for(std::map::const_iterator it(_incoming_file_hashes.begin());it!=_incoming_file_hashes.end();++it) - { - TurtleFileInfo finfo ; - finfo.name = it->second.name ; - finfo.size = it->second.size ; - finfo.hash = it->first ; -#ifdef P3TURTLE_DEBUG - std::cerr << " Saving item " << finfo.name << ", " << finfo.hash << ", " << finfo.size << std::endl ; -#endif + RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ; + RsTlvKeyValue kv; + kv.key = "TURTLE_CONFIG_MAX_TR_RATE" ; + + std::ostringstream s ; + s << _max_tr_up_rate; + kv.value = s.str() ; + vitem->tlvkvs.pairs.push_back(kv) ; + + lst.push_back(vitem) ; - item->result.push_back(finfo) ; - } - lst.push_back(item) ; -#endif return true ; } -#ifdef TO_REMOVE -bool p3turtle::loadList(std::list load) +bool p3turtle::loadList(std::list& load) { #ifdef P3TURTLE_DEBUG std::cerr << "p3turtle: loading list..." << std::endl ; #endif for(std::list::const_iterator it(load.begin());it!=load.end();++it) { - RsTurtleSearchResultItem *item = dynamic_cast(*it) ; - #ifdef P3TURTLE_DEBUG assert(item!=NULL) ; #endif - if(item == NULL) - continue ; + RsConfigKeyValueSet *vitem = dynamic_cast(*it) ; - for(std::list::const_iterator it2(item->result.begin());it2!=item->result.end();++it2) - { -#ifdef P3TURTLE_DEBUG - std::cerr << " Restarting tunneling for: " << it2->hash << " " << it2->size << " " << it2->name << std::endl ; + if(vitem != NULL) + for(std::list::const_iterator kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); ++kit) + if(kit->key == "TURTLE_CONFIG_MAX_TR_RATE") + { +#ifdef CHAT_DEBUG + std::cerr << "Loaded config default nick name for chat: " << kit->value << std::endl ; #endif - monitorFileTunnels(it2->name,it2->hash,it2->size) ; - } - delete item ; + std::istringstream is(kit->value) ; + + int val ; + is >> val ; + + setMaxTRForwardRate(val) ; + } + + delete vitem ; } return true ; } -#endif +int p3turtle::getMaxTRForwardRate() const +{ + RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/ + return _max_tr_up_rate ; +} + + +void p3turtle::setMaxTRForwardRate(int val) +{ + RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/ + + if(val > MAX_TR_FORWARD_PER_SEC_UPPER_LIMIT || val < MAX_TR_FORWARD_PER_SEC_LOWER_LIMIT) + std::cerr << "Warning: MAX_TR_FORWARD_PER_SEC value " << val << " read in config file is off limits [" << MAX_TR_FORWARD_PER_SEC_LOWER_LIMIT << "..." << MAX_TR_FORWARD_PER_SEC_UPPER_LIMIT << "]. Ignoring!" << std::endl; + else + { + _max_tr_up_rate = val ; + std::cerr << "p3turtle: Set max tr up rate to " << val << std::endl; + } + IndicateConfigChanged() ; +} // -----------------------------------------------------------------------------------// @@ -1591,7 +1611,7 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item) RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/ _traffic_info_buffer.tr_dn_Bps += static_cast(item)->serial_size() ; - float distance_to_maximum = std::min(100.0f,_traffic_info.tr_up_Bps/(float)(TUNNEL_REQUEST_PACKET_SIZE*MAX_TR_FORWARD_PER_SEC)) ; + float distance_to_maximum = std::min(100.0f,_traffic_info.tr_up_Bps/(float)(TUNNEL_REQUEST_PACKET_SIZE*_max_tr_up_rate)) ; float corrected_distance = pow(distance_to_maximum,DISTANCE_SQUEEZING_POWER) ; forward_probability = pow(depth_peer_probability[std::min((uint16_t)6,item->depth)],corrected_distance) ; #ifdef P3TURTLE_DEBUG @@ -2157,7 +2177,7 @@ void p3turtle::getTrafficStatistics(TurtleTrafficStatisticsInfo& info) const RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/ info = _traffic_info ; - float distance_to_maximum = std::min(100.0f,info.tr_up_Bps/(float)(TUNNEL_REQUEST_PACKET_SIZE*MAX_TR_FORWARD_PER_SEC)) ; + float distance_to_maximum = std::min(100.0f,info.tr_up_Bps/(float)(TUNNEL_REQUEST_PACKET_SIZE*_max_tr_up_rate)) ; info.forward_probabilities.clear() ; for(int i=0;i<=6;++i) diff --git a/libretroshare/src/turtle/p3turtle.h b/libretroshare/src/turtle/p3turtle.h index a19cfa097..f65c8c691 100644 --- a/libretroshare/src/turtle/p3turtle.h +++ b/libretroshare/src/turtle/p3turtle.h @@ -250,14 +250,6 @@ class p3turtle: public p3Service, /*public pqiMonitor,*/ public RsTurtle,/* publ virtual void getTrafficStatistics(TurtleTrafficStatisticsInfo& info) const ; -#ifdef TO_REMOVE - /************* from pqiMonitor *******************/ - /// Informs the turtle router that some peers are (dis)connected. This should initiate digging new tunnels, - /// and closing other tunnels. - /// - virtual void statusChange(const std::list &plist); -#endif - /************* from pqiMonitor *******************/ /// This function does many things: @@ -271,13 +263,17 @@ class p3turtle: public p3Service, /*public pqiMonitor,*/ public RsTurtle,/* publ /************* from p3Config *******************/ virtual RsSerialiser *setupSerialiser() ; virtual bool saveList(bool& cleanup, std::list&) ; - virtual bool loadList(std::list& /*load*/) { return true; } + virtual bool loadList(std::list& /*load*/) ; /************* Communication with ftserver *******************/ /// Does the turtle router manages tunnels to this peer ? (this is not a /// real id, but a fake one, that the turtle router is capable of connecting with a tunnel id). virtual bool isTurtlePeer(const std::string& peer_id) const ; + /// sets/gets the max number of forwarded tunnel requests per second. + virtual void setMaxTRForwardRate(int max_tr_up_rate) ; + virtual int getMaxTRForwardRate() const ; + /// Examines the peer id, finds the turtle tunnel in it, and respond yes if the tunnel is ok and operational. bool isOnline(const std::string& peer_id) const ; @@ -418,6 +414,8 @@ class p3turtle: public p3Service, /*public pqiMonitor,*/ public RsTurtle,/* publ TurtleTrafficStatisticsInfoOp _traffic_info ; // used for recording speed TurtleTrafficStatisticsInfoOp _traffic_info_buffer ; // used as a buffer to collect bytes + float _max_tr_up_rate ; + #ifdef P3TURTLE_DEBUG // debug function void dumpState() ; diff --git a/retroshare-gui/src/gui/settings/ServerPage.cpp b/retroshare-gui/src/gui/settings/ServerPage.cpp index 902952e40..6bb6383c5 100755 --- a/retroshare-gui/src/gui/settings/ServerPage.cpp +++ b/retroshare-gui/src/gui/settings/ServerPage.cpp @@ -30,6 +30,7 @@ #include #include +#include #include @@ -42,6 +43,7 @@ ServerPage::ServerPage(QWidget * parent, Qt::WFlags flags) connect( ui.netModeComboBox, SIGNAL( activated ( int ) ), this, SLOT( toggleUPnP( ) ) ); connect( ui.allowIpDeterminationCB, SIGNAL( toggled( bool ) ), this, SLOT( toggleIpDetermination(bool) ) ); connect( ui.allowTunnelConnectionCB, SIGNAL( toggled( bool ) ), this, SLOT( toggleTunnelConnection(bool) ) ); + connect( ui._max_tr_up_per_sec_SB, SIGNAL( valueChanged( int ) ), this, SLOT( updateMaxTRUpRate(int) ) ); QTimer *timer = new QTimer(this); timer->connect(timer, SIGNAL(timeout()), this, SLOT(updateStatus())); @@ -74,6 +76,11 @@ ServerPage::ServerPage(QWidget * parent, Qt::WFlags flags) #endif } +void ServerPage::updateMaxTRUpRate(int b) +{ + rsTurtle->setMaxTRForwardRate(b) ; +} + void ServerPage::toggleIpDetermination(bool b) { rsPeers->allowServerIPDetermination(b) ; @@ -185,6 +192,8 @@ void ServerPage::load() ui.dynDNS -> setText(QString::fromStdString(detail.dyndns)); ui.showDiscStatusBar->setChecked(Settings->getStatusBarFlags() & STATUSBAR_DISC); + + ui._max_tr_up_per_sec_SB->setValue(rsTurtle->getMaxTRForwardRate()) ; } /** Loads the settings for this page */ diff --git a/retroshare-gui/src/gui/settings/ServerPage.h b/retroshare-gui/src/gui/settings/ServerPage.h index 05ec80f5c..47fa33614 100755 --- a/retroshare-gui/src/gui/settings/ServerPage.h +++ b/retroshare-gui/src/gui/settings/ServerPage.h @@ -46,6 +46,7 @@ private slots: void toggleUPnP(); void toggleIpDetermination(bool) ; void toggleTunnelConnection(bool) ; + void updateMaxTRUpRate(int) ; private: Ui::ServerPage ui; diff --git a/retroshare-gui/src/gui/settings/ServerPage.ui b/retroshare-gui/src/gui/settings/ServerPage.ui index 5b9950c8f..28e473875 100755 --- a/retroshare-gui/src/gui/settings/ServerPage.ui +++ b/retroshare-gui/src/gui/settings/ServerPage.ui @@ -831,6 +831,75 @@ behind a firewall or a VPN. + + + Turtle router + + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Warning</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-weight:600;"></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;"> </span>This tab contains hard-core parameters which are unlikely to need modification. Dont change them unless you really know what you're doing. </p></body></html> + + + + + + + + + Max average tunnel request forwarded per second: + + + + + + + This value controls how many tunnel request your peer can forward per second. + +If you have a large internet bandwidth, you may raise this up to 30-40, to allow +statisticlly longuer tunnels to pass. Be very careful though, since this generates +many small packets that can significantly slow down your own file transfer. + +The default value is 20. + + + 5 + + + 100 + + + 1 + + + 20 + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + +