[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [vidalia/alpha] Add a way to set and unset routers from the list as Exit nodes
commit 944e2d63e6b510b85b9c6895dfa31629e305326c
Author: Tomás Touceda <chiiph@xxxxxxxxxxxxxx>
Date: Sat Jun 9 13:08:05 2012 -0300
Add a way to set and unset routers from the list as Exit nodes
Display routers in different colors in the list based on wether they are exit,
or they are an explicit selected exit or they are a different kind of nodes.
Also, add a way to display the router info dialog when not using Marble.
---
src/vidalia/network/NetViewer.cpp | 2 +
src/vidalia/network/RouterListItem.cpp | 57 ++++++++++++++++++++++++
src/vidalia/network/RouterListItem.h | 13 ++++++
src/vidalia/network/RouterListWidget.cpp | 70 +++++++++++++++++++++++++++++-
src/vidalia/network/RouterListWidget.h | 7 +++
5 files changed, 148 insertions(+), 1 deletions(-)
diff --git a/src/vidalia/network/NetViewer.cpp b/src/vidalia/network/NetViewer.cpp
index 1571de1..eb39ac8 100644
--- a/src/vidalia/network/NetViewer.cpp
+++ b/src/vidalia/network/NetViewer.cpp
@@ -161,6 +161,8 @@ NetViewer::NetViewer(QWidget *parent)
this, SLOT(onRouterSearch()));
connect(ui.lineRouterSearch, SIGNAL(textChanged(QString)),
ui.treeRouterList, SLOT(onRouterSearch(QString)));
+ connect(ui.treeRouterList, SIGNAL(displayRouterInfo(QString)),
+ this, SLOT(displayRouterInfo(QString)));
setupGeoIpResolver();
diff --git a/src/vidalia/network/RouterListItem.cpp b/src/vidalia/network/RouterListItem.cpp
index e26cb94..3a961b4 100644
--- a/src/vidalia/network/RouterListItem.cpp
+++ b/src/vidalia/network/RouterListItem.cpp
@@ -16,12 +16,19 @@
#include "RouterListItem.h"
#include "RouterListWidget.h"
+#include "TorSettings.h"
+#include "Vidalia.h"
+
#include <QHeaderView>
#define STATUS_COLUMN (RouterListWidget::StatusColumn)
#define COUNTRY_COLUMN (RouterListWidget::CountryColumn)
#define NAME_COLUMN (RouterListWidget::NameColumn)
+#define NONEXIT_COLOR (Qt::white)
+#define EXIT_COLOR (QColor::fromRgb(169, 207, 84))
+#define CANBEEXIT_COLOR (QColor::fromRgb(172, 209, 233))
+
#define IMG_NODE_OFFLINE ":/images/icons/node-unresponsive.png"
#define IMG_NODE_SLEEPING ":/images/icons/node-hibernating.png"
#define IMG_NODE_NO_BW ":/images/icons/node-bw-none.png"
@@ -39,6 +46,7 @@ RouterListItem::RouterListItem(RouterListWidget *list, RouterDescriptor rd)
_rd = 0;
_countryCode = "~"; /* Force items with no country to the bottom */
setIcon(COUNTRY_COLUMN, QIcon(IMG_FLAG_UNKNOWN));
+ _selectedExit = false;
update(rd);
}
@@ -151,3 +159,52 @@ RouterListItem::operator<(const QTreeWidgetItem &other) const
return QTreeWidgetItem::operator<(other);
}
+/** Sets the whole line to the given brush */
+void
+RouterListItem::setBackground(const QBrush &brush)
+{
+ QTreeWidgetItem::setBackground(STATUS_COLUMN, brush);
+ QTreeWidgetItem::setBackground(COUNTRY_COLUMN, brush);
+ QTreeWidgetItem::setBackground(NAME_COLUMN, brush);
+}
+
+/** Sets this item's background to selected exit color if exit is true */
+void
+RouterListItem::showAsSelectedExit(bool exit)
+{
+ _selectedExit = exit;
+ TorSettings settings;
+ QStringList exitNodes = settings.exitNodes();
+ bool changed = false;
+
+ if (exit) {
+ setBackground(EXIT_COLOR);
+
+ if (exitNodes.indexOf(id()) == -1) {
+ exitNodes << id();
+ settings.setExitNodes(exitNodes);
+ changed = true;
+ }
+ } else {
+ setBackground(CANBEEXIT_COLOR);
+ exitNodes.removeAll(id());
+ settings.setExitNodes(exitNodes);
+ changed = true;
+ }
+
+ QString errmsg;
+ if (changed && !settings.apply(&errmsg)) {
+ vWarn(errmsg);
+ }
+}
+
+/** Sets this item's background to exit color if exit is true */
+void
+RouterListItem::showAsExit(bool exit)
+{
+ if (exit) {
+ setBackground(CANBEEXIT_COLOR);
+ } else {
+ setBackground(NONEXIT_COLOR);
+ }
+}
diff --git a/src/vidalia/network/RouterListItem.h b/src/vidalia/network/RouterListItem.h
index 4397947..65904dd 100644
--- a/src/vidalia/network/RouterListItem.h
+++ b/src/vidalia/network/RouterListItem.h
@@ -53,12 +53,25 @@ public:
/** Overload the comparison operator. */
virtual bool operator<(const QTreeWidgetItem &other) const;
+ /** Sets this item's background to selected exit color if exit is true */
+ void showAsSelectedExit(bool exit);
+ /** Sets this item's background to exit color if exit is true */
+ void showAsExit(bool exit);
+
+ /** Returns true if this item has been selected as exit */
+ bool selectedExit() const { return _selectedExit; }
+
private:
RouterDescriptor* _rd; /**< Descriptor for this router item. */
RouterListWidget* _list; /**< The list for this list item. */
qint64 _statusValue; /**< Value used to sort items by status. */
GeoIpRecord _location; /**< Location information for this router. */
QString _countryCode;
+
+ bool _selectedExit; /**< True if this router has been selected for exit */
+
+ /** Sets the whole line to the given brush */
+ void setBackground(const QBrush &brush);
};
#endif
diff --git a/src/vidalia/network/RouterListWidget.cpp b/src/vidalia/network/RouterListWidget.cpp
index 50a1d0c..b9a76b7 100644
--- a/src/vidalia/network/RouterListWidget.cpp
+++ b/src/vidalia/network/RouterListWidget.cpp
@@ -16,6 +16,8 @@
#include "RouterListWidget.h"
#include "RouterListItem.h"
#include "Vidalia.h"
+#include "VidaliaSettings.h"
+#include "VMessageBox.h"
#include <QHeaderView>
#include <QClipboard>
@@ -55,7 +57,7 @@ RouterListWidget::retranslateUi()
void
RouterListWidget::contextMenuEvent(QContextMenuEvent *event)
{
- QAction *action;
+ QAction *action, *routerInfoAction, *useAsExit;
QMenu *menu, *copyMenu;
QList<QTreeWidgetItem *> selected;
@@ -77,6 +79,24 @@ RouterListWidget::contextMenuEvent(QContextMenuEvent *event)
else
connect(action, SIGNAL(triggered()), this, SLOT(zoomToSelectedRelay()));
+ routerInfoAction = menu->addAction(tr("Router Info"));
+ connect(routerInfoAction, SIGNAL(triggered()), this, SLOT(displayRouterInfo()));
+
+ RouterListItem *item = static_cast<RouterListItem*>(selected.first());
+
+ useAsExit = menu->addAction(tr("Use as Exit node"));
+ if (selected.size() > 1) {
+ useAsExit->setEnabled(false);
+ } else if (item->descriptor().exitPolicy().isEmpty()) {
+ useAsExit->setEnabled(false);
+ } else {
+ if (item->selectedExit()) {
+ useAsExit->setText(tr("Do not use as Exit node"));
+ }
+
+ connect(useAsExit, SIGNAL(triggered()), this, SLOT(useAsExit()));
+ }
+
menu->exec(event->globalPos());
delete menu;
}
@@ -245,7 +265,15 @@ RouterListWidget::addRouter(const RouterDescriptor &rd)
if (item) {
item->update(rd);
} else {
+ TorSettings settings;
+ QStringList exitNodes = settings.exitNodes();
+
item = new RouterListItem(this, rd);
+ if (exitNodes.indexOf(id) == -1)
+ item->showAsExit(rd.exitPolicy().length() != 0);
+ else
+ item->showAsSelectedExit(true);
+
addTopLevelItem(item);
_idmap.insert(id, item);
}
@@ -273,3 +301,43 @@ RouterListWidget::onSelectionChanged()
emit routerSelected(descriptors);
}
+/** Called when the Display router info menu action is selected */
+void
+RouterListWidget::displayRouterInfo()
+{
+ foreach (QTreeWidgetItem *item, selectedItems()) {
+ RouterListItem *relay = dynamic_cast<RouterListItem *>(item);
+ if (relay)
+ emit displayRouterInfo(relay->id());
+ break;
+ }
+}
+
+/** Called when the Use as Exit node menu action is selected */
+void
+RouterListWidget::useAsExit()
+{
+ foreach (QTreeWidgetItem *item, selectedItems()) {
+ RouterListItem *relay = dynamic_cast<RouterListItem *>(item);
+ if (relay->descriptor().exitPolicy().length() != 0) {
+ VidaliaSettings settings;
+ if (!settings.dontWarnExitNodes()) {
+ int res = VMessageBox::question(this, tr("You are about to set a fixed Exit 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 Exit?"),
+ VMessageBox::Yes,
+ VMessageBox::No|VMessageBox::Default,
+ VMessageBox::Cancel|VMessageBox::Escape,
+ "I know what I'm doing, do not remind me", &settings,
+ SETTING_REMEMBER_DONTWARNEXIT);
+
+ if (res == VMessageBox::Yes)
+ relay->showAsSelectedExit(!relay->selectedExit());
+ } else {
+ relay->showAsSelectedExit(!relay->selectedExit());
+ }
+ }
+ }
+}
diff --git a/src/vidalia/network/RouterListWidget.h b/src/vidalia/network/RouterListWidget.h
index e16646e..5b5be3c 100644
--- a/src/vidalia/network/RouterListWidget.h
+++ b/src/vidalia/network/RouterListWidget.h
@@ -62,6 +62,9 @@ signals:
void routerSelected(QList<RouterDescriptor> rd);
/** Emitted when the user selects a router to zoom in on. */
void zoomToRouter(QString id);
+ /** Emitted when the user selects a router to display more
+ * information about */
+ void displayRouterInfo(QString id);
public slots:
/** Clears the list of router items. */
@@ -84,6 +87,10 @@ private slots:
/** Emits a zoomToRouter() signal containing the fingerprint of the
* currently selected relay. */
void zoomToSelectedRelay();
+ /** Called when the Display router info menu action is selected */
+ void displayRouterInfo();
+ /** Called when the Use as Exit node menu action is selected */
+ void useAsExit();
protected:
/** Called when the user presses a key while the list has focus. */
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits