[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r1317: Wait no more than MAX_RESOLVE_QUEUE_DELAY milliseconds after (in trunk: doc src/gui/network)
Author: edmanm
Date: 2006-10-08 17:21:01 -0400 (Sun, 08 Oct 2006)
New Revision: 1317
Modified:
trunk/doc/TODO
trunk/src/gui/network/netviewer.cpp
trunk/src/gui/network/netviewer.h
Log:
Wait no more than MAX_RESOLVE_QUEUE_DELAY milliseconds after inserting the
first IP address into the queue before flushing the queue and sending a geoip
request.
Modified: trunk/doc/TODO
===================================================================
--- trunk/doc/TODO 2006-10-08 07:06:22 UTC (rev 1316)
+++ trunk/doc/TODO 2006-10-08 21:21:01 UTC (rev 1317)
@@ -16,10 +16,6 @@
to, such as "hey, you're a server now!"
* Actually do something useful with the AUTHENTICATE command, rather than
simply sending an empty one.
- * Our queue of GeoIP requests should have two timers: one long one starts
- when the first item is inserted into the queue and one shorter one that is
- reset every time an item is added to the queue. We would flush the queue
- whenever the first one expires. (Currently we just do the latter)
* GeoIP requests should be encrypted so the exit node does not know what is
being requested and cannot muck with the requests or responses.
* We should do a "getconf socksport" before setting a connection up through
Modified: trunk/src/gui/network/netviewer.cpp
===================================================================
--- trunk/src/gui/network/netviewer.cpp 2006-10-08 07:06:22 UTC (rev 1316)
+++ trunk/src/gui/network/netviewer.cpp 2006-10-08 21:21:01 UTC (rev 1317)
@@ -41,7 +41,10 @@
/** Number of milliseconds to wait after the arrival of the last descriptor whose
* IP needs to be resolved to geographic information, in case more descriptors
* arrive. Then we can simply lump the IPs into a single request. */
-#define RESOLVE_QUEUE_DELAY 3000
+#define MIN_RESOLVE_QUEUE_DELAY 3000
+/** Maximum number of milliseconds to wait after the arrival of the first
+ * IP address into the resolve queue, before we flush the entire queue. */
+#define MAX_RESOLVE_QUEUE_DELAY 10000
/** Constructor. Loads settings from VidaliaSettings.
@@ -88,11 +91,13 @@
_refreshTimer.setInterval(60*60*1000);
connect(&_refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
- /* Set up the timer used to group together GeoIP requests for new
- * descriptors arriving within RESOLVE_QUEUE_DELAY milliseconds of each
- * other. */
- _resolveQueueTimer.setSingleShot(true);
- connect(&_resolveQueueTimer, SIGNAL(timeout()), this, SLOT(resolve()));
+ /* Set up the timers used to group together GeoIP requests for new
+ * descriptors arriving within MIN_RESOLVE_QUEUE_DELAY milliseconds, but no
+ * more than MAX_RESOLVE_QUEUE_DELAY milliseconds of each other. */
+ _minResolveQueueTimer.setSingleShot(true);
+ connect(&_minResolveQueueTimer, SIGNAL(timeout()), this, SLOT(resolve()));
+ _maxResolveQueueTimer.setSingleShot(true);
+ connect(&_maxResolveQueueTimer, SIGNAL(timeout()), this, SLOT(resolve()));
/* Connect the necessary slots and signals */
connect(ui.actionHelp, SIGNAL(triggered()), this, SLOT(help()));
@@ -275,22 +280,33 @@
ui.treeRouterList->addRouter(rd);
/* Add this IP to a list whose geographic location we'd like to find. */
- QHostAddress ip(rd.ip());
+ addToResolveQueue(QHostAddress(rd.ip()), rd.id());
+}
+
+/** Adds an IP address to the resolve queue and updates the queue timers. */
+void
+NetViewer::addToResolveQueue(QHostAddress ip, QString id)
+{
+ QString ipstr = ip.toString();
if (!_resolveQueue.contains(ip)) {
+ /* Add the IP to the queue of IPs waiting for geographic information */
_resolveQueue << ip;
+
+ /* Wait MIN_RESOLVE_QUEUE_DELAY after the last item inserted into the
+ * queue, before sending the resolve request. */
+ _minResolveQueueTimer.start(MIN_RESOLVE_QUEUE_DELAY);
+
+ /* Do not wait longer than MAX_RESOLVE_QUEUE_DELAY from the time the first
+ * item is inserted into the queue, before flushing and resolving the
+ * queue. */
+ if (_resolveQueue.size() == 1) {
+ _maxResolveQueueTimer.start(MAX_RESOLVE_QUEUE_DELAY);
+ }
}
- if (!_resolveMap.values(rd.ip()).contains(rd.id())) {
- _resolveMap.insertMulti(rd.ip(), rd.id());
+ if (!_resolveMap.values(ipstr).contains(id)) {
+ /* Remember which server ids belog to which IP addresses */
+ _resolveMap.insertMulti(ipstr, id);
}
-
- /* If there are any IPs in the list, then start a timer. We delay resolution
- * because it's likely that we'll receive new descriptors shortly, so we
- * might as well lump them into a single request. */
- if (!_resolveQueue.isEmpty()) {
- /* Wait RESOLVE_QUEUE_DELAY after the <i>last</i> item inserted into the
- * queue, before sending the resolve request. */
- _resolveQueueTimer.start(RESOLVE_QUEUE_DELAY);
- }
}
/** Called when the user selects a circuit from the circuit and streams
@@ -334,8 +350,11 @@
NetViewer::resolve()
{
if (!_resolveQueue.isEmpty()) {
+ /* Flush the resolve queue and stop the timers */
_geoip.resolve(_resolveQueue);
_resolveQueue.clear();
+ _minResolveQueueTimer.stop();
+ _maxResolveQueueTimer.stop();
}
}
Modified: trunk/src/gui/network/netviewer.h
===================================================================
--- trunk/src/gui/network/netviewer.h 2006-10-08 07:06:22 UTC (rev 1316)
+++ trunk/src/gui/network/netviewer.h 2006-10-08 21:21:01 UTC (rev 1317)
@@ -84,6 +84,8 @@
void resolve();
private:
+ /** Adds an IP address to the resolve queue and updates the queue timers. */
+ void addToResolveQueue(QHostAddress ip, QString id);
/** Loads a list of router descriptors from the list of IDs. */
void loadDescriptors(QStringList ids);
/** Adds a router to our list of servers and retrieves geographic location
@@ -108,8 +110,13 @@
QList<QHostAddress> _resolveQueue;
/** Maps pending GeoIP requests to server IDs. */
QHash<QString, QString> _resolveMap;
- /** Timer used to delay GeoIP requests until we've received "a chunk" of them. */
- QTimer _resolveQueueTimer;
+ /** Timer used to delay GeoIP requests for MIN_RESOLVE_QUEUE_DELAY
+ * milliseconds after we've inserted the last item into the queue. */
+ QTimer _minResolveQueueTimer;
+ /** Timer used to limit the delay of GeoIP requests to
+ * MAX_RESOLVE_QUEUE_DELAY milliseconds after inserting the first item
+ * into the queue. */
+ QTimer _maxResolveQueueTimer;
/** Qt Designer generated object **/
Ui::NetViewer ui;