commit b73d1cb047a4d478550fe946d2be1360da1e7367 Author: Tomás Touceda chiiph@torproject.org Date: Tue Jun 12 20:19:46 2012 -0300
Allow picking entry nodes --- changes/pickExitNodes | 6 ++-- src/vidalia/config/AdvancedPage.cpp | 2 + src/vidalia/config/TorSettings.cpp | 27 +++++++++++++++++++ src/vidalia/config/TorSettings.h | 5 +++ src/vidalia/config/VidaliaSettings.cpp | 12 ++++++++ src/vidalia/config/VidaliaSettings.h | 8 ++++++ src/vidalia/network/RouterListItem.cpp | 31 ++++++++++++++++++++++ src/vidalia/network/RouterListItem.h | 7 +++++ src/vidalia/network/RouterListWidget.cpp | 41 +++++++++++++++++++++++++++++- src/vidalia/network/RouterListWidget.h | 2 + 10 files changed, 137 insertions(+), 4 deletions(-)
diff --git a/changes/pickExitNodes b/changes/pickExitNodes index 32ebd1a..8751db8 100644 --- a/changes/pickExitNodes +++ b/changes/pickExitNodes @@ -1,9 +1,9 @@ New features: - o Provide a way of hand picking exit nodes from the router list in - the Network Map. + o Provide a way of hand picking entry and exit nodes from the + router list in the Network Map.
Internal cleanups and improvements: o Fix return value from VMessageBox::question. o Make TorControl::getRouterDescriptorText() default to regular descriptors in case the microdescriptor is not available. - o Improve handling of ControlPort and SocksPort settings. \ No newline at end of file + o Improve handling of ControlPort and SocksPort settings. diff --git a/src/vidalia/config/AdvancedPage.cpp b/src/vidalia/config/AdvancedPage.cpp index 51214a4..a97c079 100644 --- a/src/vidalia/config/AdvancedPage.cpp +++ b/src/vidalia/config/AdvancedPage.cpp @@ -272,6 +272,8 @@ AdvancedPage::load()
/** We need to keep the ExitNodes settings, even if we don't use it here */ _settings->setExitNodes(_settings->exitNodes()); + /** ... and the same for entry nodes */ + _settings->setEntryNodes(_settings->entryNodes()); }
/** Called when the user selects a different authentication method from the diff --git a/src/vidalia/config/TorSettings.cpp b/src/vidalia/config/TorSettings.cpp index df56b12..c1dcb1a 100644 --- a/src/vidalia/config/TorSettings.cpp +++ b/src/vidalia/config/TorSettings.cpp @@ -49,6 +49,7 @@ #define SETTING_AUTOCONTROL "AutoControl" #define SETTING_DISABLE_NETWORK "DisableNetwork" #define SETTING_EXITNODES "ExitNodes" +#define SETTING_ENTRYNODES "EntryNodes"
/** Default to using hashed password authentication */ #define DEFAULT_AUTH_METHOD PasswordAuth @@ -176,6 +177,14 @@ TorSettings::apply(QString *errmsg) torrc->setValue(SETTING_EXITNODES, exitNodes); }
+ QString entryNodes = volatileValue(SETTING_ENTRYNODES).toString(); + + if (entryNodes.isEmpty()) { + torrc->clear(QStringList() << SETTING_ENTRYNODES); + } else { + torrc->setValue(SETTING_ENTRYNODES, entryNodes); + } + return torrc->apply(Vidalia::torControl(), errmsg); }
@@ -606,3 +615,21 @@ TorSettings::setExitNodes(const QStringList &exitNodes) { setVolatileValue(SETTING_EXITNODES, exitNodes.join(",")); } + +/** Returns the selected entry nodes */ +QStringList +TorSettings::entryNodes() const +{ + QStringList entryNodes; + with_torrc_value(SETTING_ENTRYNODES) { + entryNodes = ret.at(0).split(","); + } + return entryNodes; +} + +/** Sets the entry nodes to the specified list */ +void +TorSettings::setEntryNodes(const QStringList &entryNodes) +{ + setVolatileValue(SETTING_ENTRYNODES, entryNodes.join(",")); +} diff --git a/src/vidalia/config/TorSettings.h b/src/vidalia/config/TorSettings.h index a8c6e06..e995ba7 100644 --- a/src/vidalia/config/TorSettings.h +++ b/src/vidalia/config/TorSettings.h @@ -154,6 +154,11 @@ public: /** Sets the exit nodes to the specified list */ void setExitNodes(const QStringList &exitNodes);
+ /** Returns the selected entry nodes */ + QStringList entryNodes() const; + /** Sets the entry nodes to the specified list */ + void setEntryNodes(const QStringList &entryNodes); + private: /** Returns the AuthenticationMethod enum value for the string * description of the authentication method given in <b>authMethod</b>. */ diff --git a/src/vidalia/config/VidaliaSettings.cpp b/src/vidalia/config/VidaliaSettings.cpp index 8386d64..03dde13 100644 --- a/src/vidalia/config/VidaliaSettings.cpp +++ b/src/vidalia/config/VidaliaSettings.cpp @@ -393,3 +393,15 @@ VidaliaSettings::setDontWarnExitNodes(bool val) { setValue(SETTING_REMEMBER_DONTWARNEXIT, val); } + +bool +VidaliaSettings::dontWarnEntryNodes() const +{ + return value(SETTING_REMEMBER_DONTWARNENTRY).toBool(); +} + +void +VidaliaSettings::setDontWarnEntryNodes(bool val) +{ + setValue(SETTING_REMEMBER_DONTWARNENTRY, val); +} diff --git a/src/vidalia/config/VidaliaSettings.h b/src/vidalia/config/VidaliaSettings.h index 68cbd3b..43a9600 100644 --- a/src/vidalia/config/VidaliaSettings.h +++ b/src/vidalia/config/VidaliaSettings.h @@ -23,6 +23,7 @@ /** Public setting keys */ #define SETTING_REMEMBER_SHUTDOWN "RememberShutdown" #define SETTING_REMEMBER_DONTWARNEXIT "DontWarnExitNodes" +#define SETTING_REMEMBER_DONTWARNENTRY "DontWarnEntryNodes"
/** Handles saving and restoring Vidalia's settings, such as the * location of Tor, the control port, etc. @@ -159,6 +160,13 @@ public: /** Sets wether Vidalia should warn the user when setting Exit nodes * by hand */ void setDontWarnExitNodes(bool val); + + /** Returns true if Vidalia should warn the user when setting Entry + * nodes by hand */ + bool dontWarnEntryNodes() const; + /** Sets wether Vidalia should warn the user when setting Entry nodes + * by hand */ + void setDontWarnEntryNodes(bool val); };
#endif diff --git a/src/vidalia/network/RouterListItem.cpp b/src/vidalia/network/RouterListItem.cpp index 3a961b4..480d5a8 100644 --- a/src/vidalia/network/RouterListItem.cpp +++ b/src/vidalia/network/RouterListItem.cpp @@ -28,6 +28,7 @@ #define NONEXIT_COLOR (Qt::white) #define EXIT_COLOR (QColor::fromRgb(169, 207, 84)) #define CANBEEXIT_COLOR (QColor::fromRgb(172, 209, 233)) +#define ENTRY_COLOR (QColor::fromRgb(255, 144, 0))
#define IMG_NODE_OFFLINE ":/images/icons/node-unresponsive.png" #define IMG_NODE_SLEEPING ":/images/icons/node-hibernating.png" @@ -208,3 +209,33 @@ RouterListItem::showAsExit(bool exit) setBackground(NONEXIT_COLOR); } } + +/** Sets this item's background to selected entry color if entry is true */ +void +RouterListItem::showAsSelectedEntry(bool entry) +{ + _selectedEntry = entry; + TorSettings settings; + QStringList entryNodes = settings.entryNodes(); + bool changed = false; + + if (entry) { + setBackground(ENTRY_COLOR); + + if (entryNodes.indexOf(id()) == -1) { + entryNodes << id(); + settings.setEntryNodes(entryNodes); + changed = true; + } + } else { + setBackground(NONEXIT_COLOR); + entryNodes.removeAll(id()); + settings.setEntryNodes(entryNodes); + changed = true; + } + + QString errmsg; + if (changed && !settings.apply(&errmsg)) { + vWarn(errmsg); + } +} diff --git a/src/vidalia/network/RouterListItem.h b/src/vidalia/network/RouterListItem.h index 65904dd..db98364 100644 --- a/src/vidalia/network/RouterListItem.h +++ b/src/vidalia/network/RouterListItem.h @@ -61,6 +61,12 @@ public: /** Returns true if this item has been selected as exit */ bool selectedExit() const { return _selectedExit; }
+ /** Sets this item's background to selected entry color if exit is true */ + void showAsSelectedEntry(bool entry); + + /** Returns true if this item has been selected as entry */ + bool selectedEntry() const { return _selectedEntry; } + private: RouterDescriptor* _rd; /**< Descriptor for this router item. */ RouterListWidget* _list; /**< The list for this list item. */ @@ -69,6 +75,7 @@ private: QString _countryCode;
bool _selectedExit; /**< True if this router has been selected for exit */ + bool _selectedEntry; /**< True if this router has been selected for exit */
/** Sets the whole line to the given brush */ void setBackground(const QBrush &brush); diff --git a/src/vidalia/network/RouterListWidget.cpp b/src/vidalia/network/RouterListWidget.cpp index 837c025..faa9a3e 100644 --- a/src/vidalia/network/RouterListWidget.cpp +++ b/src/vidalia/network/RouterListWidget.cpp @@ -59,7 +59,7 @@ RouterListWidget::retranslateUi() void RouterListWidget::contextMenuEvent(QContextMenuEvent *event) { - QAction *action, *routerInfoAction, *useAsExit; + QAction *action, *routerInfoAction, *useAsExit, *useAsEntry; QMenu *menu, *copyMenu; QList<QTreeWidgetItem *> selected;
@@ -100,6 +100,18 @@ RouterListWidget::contextMenuEvent(QContextMenuEvent *event) connect(useAsExit, SIGNAL(triggered()), this, SLOT(useAsExit())); }
+ useAsEntry = menu->addAction(QIcon(IMG_PLUS), tr("Use as Entry node")); + if (selected.size() > 1) { + useAsEntry->setEnabled(false); + } else { + if (item->selectedEntry()) { + useAsEntry->setText(tr("Do not use as Entry node")); + useAsEntry->setIcon(QIcon(IMG_MINUS)); + } + + connect(useAsEntry, SIGNAL(triggered()), this, SLOT(useAsEntry())); + } + menu->exec(event->globalPos()); delete menu; } @@ -344,3 +356,30 @@ RouterListWidget::useAsExit() } } } + +/** Called when the Use as Entry node menu action is selected */ +void +RouterListWidget::useAsEntry() +{ + foreach (QTreeWidgetItem *item, selectedItems()) { + RouterListItem *relay = dynamic_cast<RouterListItem *>(item); + VidaliaSettings settings; + if (!settings.dontWarnEntryNodes()) { + int res = VMessageBox::question(this, tr("You are about to set a fixed Entry node"), + tr("You need to understand that by doing this you might be " + "putting your anonymity at risk and/or limiting the " + "services you have available through Tor.\n\n" + "Do you still want to set this node as Entry?"), + VMessageBox::Yes, + VMessageBox::No|VMessageBox::Default, + VMessageBox::Cancel|VMessageBox::Escape, + "I know what I'm doing, do not remind me", &settings, + SETTING_REMEMBER_DONTWARNENTRY); + + if (res == VMessageBox::Yes) + relay->showAsSelectedEntry(!relay->selectedEntry()); + } else { + relay->showAsSelectedEntry(!relay->selectedEntry()); + } + } +} diff --git a/src/vidalia/network/RouterListWidget.h b/src/vidalia/network/RouterListWidget.h index 5b5be3c..fddfaa9 100644 --- a/src/vidalia/network/RouterListWidget.h +++ b/src/vidalia/network/RouterListWidget.h @@ -91,6 +91,8 @@ private slots: void displayRouterInfo(); /** Called when the Use as Exit node menu action is selected */ void useAsExit(); + /** Called when the Use as Entry node menu action is selected */ + void useAsEntry();
protected: /** Called when the user presses a key while the list has focus. */
tor-commits@lists.torproject.org