[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[vidalia-svn] r2156: Add a TorControl::circuitEstablished() method to check if To (in trunk: . src/control)



Author: edmanm
Date: 2007-12-02 03:17:31 -0500 (Sun, 02 Dec 2007)
New Revision: 2156

Modified:
   trunk/
   trunk/src/control/torcontrol.cpp
   trunk/src/control/torcontrol.h
Log:
 r2193@lysithea:  edmanm | 2007-12-02 03:17:12 -0500
 Add a TorControl::circuitEstablished() method to check if Tor has decided it
 is able to build circuits.



Property changes on: trunk
___________________________________________________________________
 svk:merge ticket from /local/vidalia/trunk [r2193] on 0108964c-5b0b-4c9e-969f-e2288315d100

Modified: trunk/src/control/torcontrol.cpp
===================================================================
--- trunk/src/control/torcontrol.cpp	2007-12-01 17:48:14 UTC (rev 2155)
+++ trunk/src/control/torcontrol.cpp	2007-12-02 08:17:31 UTC (rev 2156)
@@ -343,6 +343,29 @@
   return pi;
 }
 
+/** Returns true if Tor either has an open circuit or (on Tor >=
+ * 0.2.0.1-alpha) has previously decided it's able to establish a circuit. */
+bool
+TorControl::circuitEstablished()
+{
+  /* If Tor is recent enough, we can 'getinfo status/circuit-established' to
+   * see if Tor has an open circuit */
+  if (getTorVersion() >= 0x020001) {
+    QString tmp;
+    if (getInfo("status/circuit-established", tmp))
+      return (tmp == "1");
+  }
+
+  /* Either Tor was too old or our getinfo failed, so try to get a list of all
+   * circuits and check their statuses. */
+  QList<Circuit> circs = getCircuits();
+  foreach (Circuit circ, circs) {
+    if (circ.status() == Circuit::Built)
+      return true;
+  }
+  return false;
+}
+
 /** Sends a GETINFO message to Tor based on the given map of keyvals. The
  * syntax is:
  * 

Modified: trunk/src/control/torcontrol.h
===================================================================
--- trunk/src/control/torcontrol.h	2007-12-01 17:48:14 UTC (rev 2155)
+++ trunk/src/control/torcontrol.h	2007-12-02 08:17:31 UTC (rev 2156)
@@ -78,7 +78,11 @@
   
   /** Sends a PROTOCOLINFO command to Tor and parses the response. */
   ProtocolInfo protocolInfo(QString *errmsg = 0);
-  
+ 
+  /** Returns true if Tor either has an open circuit or (on Tor >= 
+   * 0.2.0.1-alpha) has previously decided it's able to establish a circuit. */
+  bool circuitEstablished();
+
   /** Sends a GETINFO message to Tor based on the given keys */
   bool getInfo(QHash<QString,QString> &map, QString *errmsg = 0);
   /** Sends a GETINFO message for a single info value to Tor */