commit 6ae0b6e6aa1481718443f3e367a91d15a5bdaa6f Author: Damian Johnson atagar@torproject.org Date: Sun Jun 12 13:48:13 2011 -0700
Binding handlers for the connections submenu --- src/cli/connections/connPanel.py | 30 +++++++++++++++++----- src/cli/menu/actions.py | 50 ++++++++++++++++++++++++++++++++----- src/util/connections.py | 19 ++++++++++++++ 3 files changed, 85 insertions(+), 14 deletions(-)
diff --git a/src/cli/connections/connPanel.py b/src/cli/connections/connPanel.py index 8b86c65..9490ddc 100644 --- a/src/cli/connections/connPanel.py +++ b/src/cli/connections/connPanel.py @@ -6,6 +6,7 @@ import time import curses import threading
+import cli.controller import cli.descriptorPopup import cli.popups
@@ -124,6 +125,13 @@ class ConnectionPanel(panel.Panel, threading.Thread): self._entryLines += entry.getLines() self.valsLock.release()
+ def getListingType(self): + """ + Provides the priority content we list connections by. + """ + + return self._listingType + def setListingType(self, listingType): """ Sets the priority information presented by the panel. @@ -143,6 +151,20 @@ class ConnectionPanel(panel.Panel, threading.Thread):
self.valsLock.release()
+ def showSortDialog(self): + """ + Provides the sort dialog for our connections. + """ + + # set ordering for connection options + cli.controller.getController().requestRedraw(True) + titleLabel = "Connection Ordering:" + options = entries.SortAttr.values() + oldSelection = self._sortOrdering + optionColors = dict([(attr, entries.SORT_COLORS[attr]) for attr in options]) + results = cli.popups.showSortDialog(titleLabel, options, oldSelection, optionColors) + if results: self.setSortOrder(results) + def handleKey(self, key): self.valsLock.acquire()
@@ -156,13 +178,7 @@ class ConnectionPanel(panel.Panel, threading.Thread): self._showDetails = not self._showDetails self.redraw(True) elif key == ord('s') or key == ord('S'): - # set ordering for connection options - titleLabel = "Connection Ordering:" - options = entries.SortAttr.values() - oldSelection = self._sortOrdering - optionColors = dict([(attr, entries.SORT_COLORS[attr]) for attr in options]) - results = cli.popups.showSortDialog(titleLabel, options, oldSelection, optionColors) - if results: self.setSortOrder(results) + self.showSortDialog() elif key == ord('u') or key == ord('U'): # provides a menu to pick the connection resolver title = "Resolver Util:" diff --git a/src/cli/menu/actions.py b/src/cli/menu/actions.py index c8b8da3..2827742 100644 --- a/src/cli/menu/actions.py +++ b/src/cli/menu/actions.py @@ -8,7 +8,7 @@ import cli.controller import cli.menu.item import cli.graphing.graphPanel
-from util import torTools, uiTools +from util import connections, torTools, uiTools
def makeMenu(): """ @@ -26,12 +26,8 @@ def makeMenu(): baseMenu.add(makeGraphMenu(pagePanel)) elif pagePanel.getName() == "log": baseMenu.add(makeLogMenu(pagePanel)) - - connectionsMenu = cli.menu.item.Submenu("Connections") - connectionsMenu.add(cli.menu.item.MenuItem("Identity", None)) - connectionsMenu.add(cli.menu.item.MenuItem("Resolver", None)) - connectionsMenu.add(cli.menu.item.MenuItem("Sort Order", None)) - baseMenu.add(connectionsMenu) + elif pagePanel.getName() == "connections": + baseMenu.add(makeConnectionsMenu(pagePanel))
configurationMenu = cli.menu.item.Submenu("Configuration")
@@ -188,5 +184,45 @@ def makeLogMenu(logPanel): logMenu.add(filterMenu)
return logMenu + +def makeConnectionsMenu(connPanel): + """ + Submenu for the connections panel, consisting of... + [X] IP Address + [ ] Fingerprint + [ ] Nickname + Sorting... + Resolver (Submenu) + + Arguments: + connPanel - instance of the connections panel + """ + + connectionsMenu = cli.menu.item.Submenu("Connections") + + # listing options + listingGroup = cli.menu.item.SelectionGroup(connPanel.setListingType, connPanel.getListingType()) + + listingOptions = cli.connections.entries.ListingType.values() + listingOptions.remove(cli.connections.entries.ListingType.HOSTNAME) + + for option in listingOptions: + connectionsMenu.add(cli.menu.item.SelectionMenuItem(option, listingGroup, option)) + + # sorting option + connectionsMenu.add(cli.menu.item.MenuItem("Sorting...", connPanel.showSortDialog)) + + # resolver submenu + connResolver = connections.getResolver("tor") + resolverMenu = cli.menu.item.Submenu("Resolver") + resolverGroup = cli.menu.item.SelectionGroup(connResolver.setOverwriteResolver, connResolver.getOverwriteResolver()) + + resolverMenu.add(cli.menu.item.SelectionMenuItem("auto", resolverGroup, None)) + + for option in connections.Resolver.values(): + resolverMenu.add(cli.menu.item.SelectionMenuItem(option, resolverGroup, option)) + + connectionsMenu.add(resolverMenu)
+ return connectionsMenu
diff --git a/src/util/connections.py b/src/util/connections.py index 47aa8af..97de3ea 100644 --- a/src/util/connections.py +++ b/src/util/connections.py @@ -444,6 +444,25 @@ class ConnectionResolver(threading.Thread): # avoid having stray spikes up the rate. self._rateThresholdBroken = 0
+ def getOverwriteResolver(self): + """ + Provides the resolver connection resolution is forced to use. This returns + None if it's dynamically determined. + """ + + return self.overwriteResolver + + def setOverwriteResolver(self, overwriteResolver): + """ + Sets the resolver used for connection resolution, if None then this is + automatically determined based on what is available. + + Arguments: + overwriteResolver - connection resolver to be used + """ + + self.overwriteResolver = overwriteResolver + def run(self): while not self._halt: minWait = self.resolveRate if self.resolveRate else self.defaultRate
tor-commits@lists.torproject.org