From 90415627a228b71ed5db7c138eb2edd0cf72bb84 Mon Sep 17 00:00:00 2001 From: drbob Date: Sun, 25 Nov 2012 22:49:00 +0000 Subject: [PATCH] * Added second (temporary) switch to turtle. * Use session switch for OperatingMode. * made OperatingMode temporary - not saved. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5895 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/retroshare/rsconfig.h | 4 +-- libretroshare/src/retroshare/rsturtle.h | 5 +++ libretroshare/src/rsserver/p3serverconfig.cc | 33 ++++++++++++++++++++ libretroshare/src/rsserver/p3serverconfig.h | 1 + libretroshare/src/turtle/p3turtle.cc | 25 +++++++++++++-- libretroshare/src/turtle/p3turtle.h | 6 ++++ 6 files changed, 70 insertions(+), 4 deletions(-) diff --git a/libretroshare/src/retroshare/rsconfig.h b/libretroshare/src/retroshare/rsconfig.h index 0bc6a9fc8..b1e8ebe55 100644 --- a/libretroshare/src/retroshare/rsconfig.h +++ b/libretroshare/src/retroshare/rsconfig.h @@ -119,8 +119,8 @@ extern RsServerConfig *rsConfig; #define RS_OPMODE_FULL 0x0001 #define RS_OPMODE_NOTURTLE 0x0002 -#define RS_OPMODE_GAMING 0x0004 -#define RS_OPMODE_MINIMAL 0x0008 +#define RS_OPMODE_GAMING 0x0003 +#define RS_OPMODE_MINIMAL 0x0004 class RsConfigStartup diff --git a/libretroshare/src/retroshare/rsturtle.h b/libretroshare/src/retroshare/rsturtle.h index 232050594..29d7ccdc3 100644 --- a/libretroshare/src/retroshare/rsturtle.h +++ b/libretroshare/src/retroshare/rsturtle.h @@ -88,9 +88,14 @@ class RsTurtle RsTurtle() {} virtual ~RsTurtle() {} + // This is saved permanently. virtual void setEnabled(bool) = 0 ; virtual bool enabled() const = 0 ; + // This is temporary, used by Operating Mode. + virtual void setSessionEnabled(bool) = 0 ; + virtual bool sessionEnabled() const = 0 ; + // Lauches a search request through the pipes, and immediately returns // the request id, which will be further used by the gui to store results // as they come back. diff --git a/libretroshare/src/rsserver/p3serverconfig.cc b/libretroshare/src/rsserver/p3serverconfig.cc index 31daa9000..b6a5e313b 100644 --- a/libretroshare/src/rsserver/p3serverconfig.cc +++ b/libretroshare/src/rsserver/p3serverconfig.cc @@ -23,6 +23,7 @@ * */ +#include #include "rsserver/p3serverconfig.h" #include "services/p3bwctrl.h" @@ -46,10 +47,14 @@ p3ServerConfig::p3ServerConfig(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr, p3NetMgr mGeneralConfig = genCfg; + RsStackMutex stack(configMtx); /******* LOCKED MUTEX *****/ + mUserLevel = RSCONFIG_USER_LEVEL_NEW; /* START LEVEL */ mRateDownload = DEFAULT_DOWNLOAD_KB_RATE; mRateUpload = DEFAULT_UPLOAD_KB_RATE; + mOpMode = RS_OPMODE_FULL; + rsConfig = this; } @@ -320,6 +325,7 @@ uint32_t p3ServerConfig::getConnectModes() uint32_t p3ServerConfig::getOperatingMode() { +#ifdef SAVE_OPERATING_MODE std::string modestr = mGeneralConfig->getSetting(RS_CONFIG_OPERATING_STRING); uint32_t mode = RS_OPMODE_FULL; @@ -340,11 +346,16 @@ uint32_t p3ServerConfig::getOperatingMode() mode = RS_OPMODE_MINIMAL; } return mode; +#else + RsStackMutex stack(configMtx); /******* LOCKED MUTEX *****/ + return mOpMode; +#endif } bool p3ServerConfig::setOperatingMode(uint32_t opMode) { +#ifdef SAVE_OPERATING_MODE std::string modestr = "FULL"; switch(opMode) { @@ -364,6 +375,12 @@ bool p3ServerConfig::setOperatingMode(uint32_t opMode) break; } mGeneralConfig->setSetting(RS_CONFIG_OPERATING_STRING, modestr); +#else + { + RsStackMutex stack(configMtx); /******* LOCKED MUTEX *****/ + mOpMode = opMode; + } +#endif return switchToOperatingMode(opMode); } @@ -372,6 +389,7 @@ bool p3ServerConfig::switchToOperatingMode(uint32_t opMode) { float dl_rate = 0; float ul_rate = 0; + bool turtle_enabled = true; { RsStackMutex stack(configMtx); /******* LOCKED MUTEX *****/ @@ -379,6 +397,9 @@ bool p3ServerConfig::switchToOperatingMode(uint32_t opMode) ul_rate = mRateUpload; } + std::cerr << "p3ServerConfig::switchToOperatingMode(" << opMode << ")"; + std::cerr << std::endl; + switch (opMode) { default: @@ -388,17 +409,20 @@ bool p3ServerConfig::switchToOperatingMode(uint32_t opMode) /* switch on popups, enable hashing */ //setMaxRate(true, mri); // In / Download //setMaxRate(false, mro); // Out / Upload. + turtle_enabled = true; break; case RS_OPMODE_NOTURTLE: /* switch on all transfers - except turtle, enable hashing */ /* 100% bandwidth */ /* switch on popups, enable hashing */ + turtle_enabled = false; break; case RS_OPMODE_GAMING: /* switch on all transfers */ /* reduce bandwidth to 25% */ /* switch off popups, enable hashing */ + turtle_enabled = true; dl_rate *= 0.25; ul_rate *= 0.25; @@ -408,6 +432,7 @@ bool p3ServerConfig::switchToOperatingMode(uint32_t opMode) /* reduce bandwidth to 10%, but make sure there is enough for VoIP */ /* switch on popups, enable hashing */ + turtle_enabled = false; dl_rate *= 0.10; ul_rate *= 0.10; @@ -427,8 +452,16 @@ bool p3ServerConfig::switchToOperatingMode(uint32_t opMode) { mPqiHandler -> setMaxRate(true, dl_rate); mPqiHandler -> setMaxRate(false, ul_rate); + + std::cerr << "p3ServerConfig::switchToOperatingMode() D/L: " << dl_rate << " U/L: " << ul_rate; + std::cerr << std::endl; + } + std::cerr << "p3ServerConfig::switchToOperatingMode() Turtle Mode: " << turtle_enabled; + std::cerr << std::endl; + + rsTurtle->setSessionEnabled(turtle_enabled); return true; } diff --git a/libretroshare/src/rsserver/p3serverconfig.h b/libretroshare/src/rsserver/p3serverconfig.h index b892337aa..8a65ddeb9 100644 --- a/libretroshare/src/rsserver/p3serverconfig.h +++ b/libretroshare/src/rsserver/p3serverconfig.h @@ -114,6 +114,7 @@ bool findConfigurationOption(uint32_t key, std::string &keystr); float mRateDownload; float mRateUpload; + uint32_t mOpMode; }; #endif diff --git a/libretroshare/src/turtle/p3turtle.cc b/libretroshare/src/turtle/p3turtle.cc index 32f800cff..349485d1c 100644 --- a/libretroshare/src/turtle/p3turtle.cc +++ b/libretroshare/src/turtle/p3turtle.cc @@ -105,6 +105,8 @@ p3turtle::p3turtle(p3LinkMgr *lm,ftServer *fs) RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/ _turtle_routing_enabled = true ; + _turtle_routing_session_enabled = true; + _ft_server = fs ; _ft_controller = fs->getController() ; @@ -140,6 +142,25 @@ bool p3turtle::enabled() const return _turtle_routing_enabled ; } + +void p3turtle::setSessionEnabled(bool b) +{ + RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/ + _turtle_routing_session_enabled = b; + + if(b) + std::cerr << "Enabling turtle routing for this Session" << std::endl; + else + std::cerr << "Disabling turtle routing for this Session" << std::endl; +} + +bool p3turtle::sessionEnabled() const +{ + RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/ + return _turtle_routing_session_enabled ; +} + + int p3turtle::tick() { // Handle tunnel trafic @@ -173,7 +194,7 @@ int p3turtle::tick() #ifdef P3TURTLE_DEBUG std::cerr << "Calling tunnel management." << std::endl ; #endif - if(_turtle_routing_enabled) + if(_turtle_routing_enabled && _turtle_routing_session_enabled) manageTunnels() ; { @@ -728,7 +749,7 @@ int p3turtle::handleIncoming() { nhandled++; - if(!_turtle_routing_enabled) + if(!(_turtle_routing_enabled && _turtle_routing_session_enabled)) delete item ; else { diff --git a/libretroshare/src/turtle/p3turtle.h b/libretroshare/src/turtle/p3turtle.h index 6bfb96f01..0d22a9107 100644 --- a/libretroshare/src/turtle/p3turtle.h +++ b/libretroshare/src/turtle/p3turtle.h @@ -223,6 +223,11 @@ class p3turtle: public p3Service, public RsTurtle, public p3Config virtual void setEnabled(bool) ; virtual bool enabled() const ; + // This is temporary, used by Operating Mode. + // Turtle operates when both enabled() && sessionEnabled() are true. + virtual void setSessionEnabled(bool); + virtual bool sessionEnabled() const; + // Lauches a search request through the pipes, and immediately returns // the request id, which will be further used by the gui to store results // as they come back. @@ -431,6 +436,7 @@ class p3turtle: public p3Service, public RsTurtle, public p3Config float _max_tr_up_rate ; bool _turtle_routing_enabled ; + bool _turtle_routing_session_enabled ; #ifdef P3TURTLE_DEBUG // debug function