added global switch to enable/disable anonymous routing. This will be used for connexion profiles with very limited bandwidth

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5886 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-11-25 14:26:32 +00:00
parent 863951c589
commit fd723bcea7
6 changed files with 99 additions and 35 deletions

View File

@ -88,6 +88,9 @@ class RsTurtle
RsTurtle() {}
virtual ~RsTurtle() {}
virtual void setEnabled(bool) = 0 ;
virtual bool enabled() 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.

View File

@ -104,6 +104,7 @@ p3turtle::p3turtle(p3LinkMgr *lm,ftServer *fs)
{
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
_turtle_routing_enabled = true ;
_ft_server = fs ;
_ft_controller = fs->getController() ;
@ -121,6 +122,24 @@ p3turtle::p3turtle(p3LinkMgr *lm,ftServer *fs)
_max_tr_up_rate = MAX_TR_FORWARD_PER_SEC ;
}
void p3turtle::setEnabled(bool b)
{
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
_turtle_routing_enabled = b;
if(b)
std::cerr << "Enabling turtle routing" << std::endl;
else
std::cerr << "Disabling turtle routing" << std::endl;
IndicateConfigChanged() ;
}
bool p3turtle::enabled() const
{
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
return _turtle_routing_enabled ;
}
int p3turtle::tick()
{
// Handle tunnel trafic
@ -154,7 +173,8 @@ int p3turtle::tick()
#ifdef P3TURTLE_DEBUG
std::cerr << "Calling tunnel management." << std::endl ;
#endif
manageTunnels() ;
if(_turtle_routing_enabled)
manageTunnels() ;
{
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
@ -497,7 +517,7 @@ void p3turtle::locked_closeTunnel(TurtleTunnelId tid,std::vector<std::pair<Turtl
if(it == _local_tunnels.end())
{
std::cerr << "p3turtle: was asked to close tunnel " << (void*)tid << ", which actually doesn't exist." << std::endl ;
std::cerr << "p3turtle: was asked to close tunnel " << reinterpret_cast<void*>(tid) << ", which actually doesn't exist." << std::endl ;
return ;
}
#ifdef P3TURTLE_DEBUG
@ -593,10 +613,14 @@ bool p3turtle::saveList(bool& cleanup, std::list<RsItem*>& lst)
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ;
RsTlvKeyValue kv;
kv.key = "TURTLE_CONFIG_MAX_TR_RATE" ;
rs_sprintf(kv.value, "%g", _max_tr_up_rate);
vitem->tlvkvs.pairs.push_back(kv) ;
kv.key = "TURTLE_ENABLED" ;
kv.value = _turtle_routing_enabled?"TRUE":"FALSE" ;
vitem->tlvkvs.pairs.push_back(kv) ;
lst.push_back(vitem) ;
return true ;
@ -613,17 +637,24 @@ bool p3turtle::loadList(std::list<RsItem*>& load)
if(vitem != NULL)
for(std::list<RsTlvKeyValue>::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
int val ;
if (sscanf(kit->value.c_str(), "%d", &val) == 1)
{
setMaxTRForwardRate(val) ;
std::cerr << "Setting max TR forward rate to " << val << std::endl ;
}
}
if(kit->key == "TURTLE_ENABLED")
{
_turtle_routing_enabled = (kit->value == "TRUE") ;
if(!_turtle_routing_enabled)
std::cerr << "WARNING: turtle routing has been disabled. You can enable it again in config->server->turtle router." << std::endl;
}
}
delete vitem ;
}
@ -697,33 +728,38 @@ int p3turtle::handleIncoming()
{
nhandled++;
RsTurtleGenericTunnelItem *gti = dynamic_cast<RsTurtleGenericTunnelItem *>(item) ;
if(gti != NULL)
routeGenericTunnelItem(gti) ; /// Generic packets, that travel through established tunnels.
else /// These packets should be destroyed by the client.
if(!_turtle_routing_enabled)
delete item ;
else
{
/// Special packets that require specific treatment, because tunnels do not exist for these packets.
/// These packets are destroyed here, after treatment.
//
switch(item->PacketSubType())
RsTurtleGenericTunnelItem *gti = dynamic_cast<RsTurtleGenericTunnelItem *>(item) ;
if(gti != NULL)
routeGenericTunnelItem(gti) ; /// Generic packets, that travel through established tunnels.
else /// These packets should be destroyed by the client.
{
case RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST:
case RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST: handleSearchRequest(dynamic_cast<RsTurtleSearchRequestItem *>(item)) ;
break ;
/// Special packets that require specific treatment, because tunnels do not exist for these packets.
/// These packets are destroyed here, after treatment.
//
switch(item->PacketSubType())
{
case RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST:
case RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST: handleSearchRequest(dynamic_cast<RsTurtleSearchRequestItem *>(item)) ;
break ;
case RS_TURTLE_SUBTYPE_SEARCH_RESULT : handleSearchResult(dynamic_cast<RsTurtleSearchResultItem *>(item)) ;
break ;
case RS_TURTLE_SUBTYPE_SEARCH_RESULT : handleSearchResult(dynamic_cast<RsTurtleSearchResultItem *>(item)) ;
break ;
case RS_TURTLE_SUBTYPE_OPEN_TUNNEL : handleTunnelRequest(dynamic_cast<RsTurtleOpenTunnelItem *>(item)) ;
break ;
case RS_TURTLE_SUBTYPE_OPEN_TUNNEL : handleTunnelRequest(dynamic_cast<RsTurtleOpenTunnelItem *>(item)) ;
break ;
case RS_TURTLE_SUBTYPE_TUNNEL_OK : handleTunnelResult(dynamic_cast<RsTurtleTunnelOkItem *>(item)) ;
break ;
default:
std::cerr << "p3turtle::handleIncoming: Unknown packet subtype " << item->PacketSubType() << std::endl ;
case RS_TURTLE_SUBTYPE_TUNNEL_OK : handleTunnelResult(dynamic_cast<RsTurtleTunnelOkItem *>(item)) ;
break ;
default:
std::cerr << "p3turtle::handleIncoming: Unknown packet subtype " << item->PacketSubType() << std::endl ;
}
delete item;
}
delete item;
}
}
@ -1025,7 +1061,7 @@ void p3turtle::routeGenericTunnelItem(RsTurtleGenericTunnelItem *item)
case RS_TURTLE_SUBTYPE_CHUNK_CRC_REQUEST: handleRecvChunkCRCRequest(dynamic_cast<RsTurtleChunkCrcRequestItem *>(item)) ;
break ;
default:
std::cerr << "WARNING: Unknown packet type received: id=" << (void*)(item->PacketSubType()) << ". Is somebody trying to poison you ?" << std::endl ;
std::cerr << "WARNING: Unknown packet type received: id=" << reinterpret_cast<void*>(item->PacketSubType()) << ". Is somebody trying to poison you ?" << std::endl ;
#ifdef P3TURTLE_DEBUG
exit(-1) ;
#endif
@ -2050,7 +2086,7 @@ void p3turtle::handleTunnelResult(RsTurtleTunnelOkItem *item)
new_vpid = _local_tunnels[item->tunnel_id].vpid ; // save it for off-mutex usage.
}
if(!found)
std::cerr << "p3turtle: error. Could not find hash that emmitted tunnel request " << (void*)item->tunnel_id << std::endl ;
std::cerr << "p3turtle: error. Could not find hash that emmitted tunnel request " << reinterpret_cast<void*>(item->tunnel_id) << std::endl ;
}
else
{ // Nope, forward it back.

View File

@ -218,6 +218,11 @@ class p3turtle: public p3Service, public RsTurtle, public p3Config
public:
p3turtle(p3LinkMgr *lm,ftServer *m);
// Enables/disable the service. Still ticks, but does nothing. Default is true.
//
virtual void setEnabled(bool) ;
virtual bool enabled() 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.
@ -252,7 +257,7 @@ class p3turtle: public p3Service, public RsTurtle, public p3Config
virtual void getTrafficStatistics(TurtleTrafficStatisticsInfo& info) const ;
/************* from pqiMonitor *******************/
/************* from p3service *******************/
/// This function does many things:
/// - It handles incoming and outgoing packets
@ -425,6 +430,7 @@ class p3turtle: public p3Service, public RsTurtle, public p3Config
TurtleTrafficStatisticsInfoOp _traffic_info_buffer ; // used as a buffer to collect bytes
float _max_tr_up_rate ;
bool _turtle_routing_enabled ;
#ifdef P3TURTLE_DEBUG
// debug function

View File

@ -43,6 +43,7 @@ ServerPage::ServerPage(QWidget * parent, Qt::WFlags flags)
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) ) );
connect( ui._turtle_enabled_CB, SIGNAL( toggled( bool ) ), this, SLOT( toggleTurtleRouting(bool) ) );
QTimer *timer = new QTimer(this);
timer->connect(timer, SIGNAL(timeout()), this, SLOT(updateStatus()));
@ -193,6 +194,13 @@ void ServerPage::load()
ui.showDiscStatusBar->setChecked(Settings->getStatusBarFlags() & STATUSBAR_DISC);
ui._max_tr_up_per_sec_SB->setValue(rsTurtle->getMaxTRForwardRate()) ;
ui._turtle_enabled_CB->setChecked(rsTurtle->enabled()) ;
}
void ServerPage::toggleTurtleRouting(bool b)
{
rsTurtle->setEnabled(b) ;
}
/** Loads the settings for this page */

View File

@ -50,6 +50,7 @@ private slots:
void toggleIpDetermination(bool) ;
void toggleTunnelConnection(bool) ;
void updateMaxTRUpRate(int) ;
void toggleTurtleRouting(bool) ;
private:
Ui::ServerPage ui;

View File

@ -187,7 +187,7 @@ peers still need to trust each other to allow connection. </string>
<item row="1" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
@ -364,10 +364,10 @@ behind a firewall or a VPN.</string>
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Ubuntu'; font-size:11pt; font-weight:600;&quot;&gt;Warning&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu'; font-size:11pt; font-weight:600;&quot;&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Ubuntu'; font-size:11pt; font-weight:600;&quot;&gt; &lt;/span&gt;&lt;span style=&quot; font-family:'Ubuntu'; font-size:11pt;&quot;&gt;This tab contains hard-core parameters which are unlikely to need modification. Don't change them unless you really know what you're doing. &lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Warning&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;-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;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-weight:600;&quot;&gt; &lt;/span&gt;This tab contains hard-core parameters which are unlikely to need modification. Don't change them unless you really know what you're doing. &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
@ -407,6 +407,16 @@ The default value is 20.</string>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="_turtle_enabled_CB">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Unchecking this disables all anonymous routing activity, except cache cleaning. Incoming tunnel requests are discarded, and no tunnel requests are sent to anyone. &lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Enable anonymous data routing</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">