[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r2148: Don't block while connecting to Tor. Also rename TorSocket:: (in trunk: . src/util)
Author: edmanm
Date: 2007-12-01 02:39:48 -0500 (Sat, 01 Dec 2007)
New Revision: 2148
Modified:
trunk/
trunk/src/util/torsocket.cpp
trunk/src/util/torsocket.h
Log:
r2177@lysithea: edmanm | 2007-12-01 02:36:48 -0500
Don't block while connecting to Tor. Also rename TorSocket::connectToHost() to
the more descriptive TorSocket::connectToRemoteHost(), since the proxy is a
host too.
Property changes on: trunk
___________________________________________________________________
svk:merge ticket from /local/vidalia/trunk [r2177] on 0108964c-5b0b-4c9e-969f-e2288315d100
Modified: trunk/src/util/torsocket.cpp
===================================================================
--- trunk/src/util/torsocket.cpp 2007-12-01 03:55:42 UTC (rev 2147)
+++ trunk/src/util/torsocket.cpp 2007-12-01 07:39:48 UTC (rev 2148)
@@ -35,36 +35,30 @@
#define SOCKS_RESPONSE_LEN 0x08 /**< SOCKS server response length. */
#define SOCKS_RESPONSE_VERSION 0x00 /**< SOCKS server response version. */
#define SOCKS_CONNECT_STATUS_OK 0x5A /**< SOCKS server response status. */
-#define LOCAL_CONNECT_TIMEOUT 3000 /**< Time to wait for a connection to
- the local SOCKS proxy. */
+
/** Constructor. */
-TorSocket::TorSocket(QHostAddress socksAddr, quint16 socksPort, QObject *parent)
+TorSocket::TorSocket(const QHostAddress &socksAddr,
+ quint16 socksPort, QObject *parent)
: QTcpSocket(parent),
_socksAddr(socksAddr),
_socksPort(socksPort)
{
QObject::connect(this, SIGNAL(error(QAbstractSocket::SocketError)),
this, SLOT(onError(QAbstractSocket::SocketError)));
+ QObject::connect(this, SIGNAL(readyRead()),
+ this, SLOT(onHandshakeResponse()));
+ QObject::connect(this, SIGNAL(connected()),
+ this, SLOT(connectedToProxy()));
}
/** Connects to the specified hostname and port via Tor. */
void
-TorSocket::connectToHost(const QString &remoteHost, quint16 remotePort)
+TorSocket::connectToRemoteHost(const QString &remoteHost, quint16 remotePort)
{
- /* Connect to the local socks proxy. */
+ _remoteHost = remoteHost;
+ _remotePort = remotePort;
QTcpSocket::connectToHost(_socksAddr, _socksPort);
-
- /* Wait for the local connection. */
- if (waitForConnected(LOCAL_CONNECT_TIMEOUT)) {
- /* Signal that we connected to Tor. */
- emit connectedToTor();
-
- /* We're connected to the proxy, so send our part of the handshake. */
- QObject::connect(this, SIGNAL(readyRead()),
- this, SLOT(onHandshakeResponse()));
- sendSocksHandshake(remoteHost, remotePort);
- }
}
/** Called when a connection error has occurred. */
@@ -75,6 +69,14 @@
emit socketError(errorString());
}
+/** Called when the socket is connected to the proxy and sends our
+ * half of a Socks4a handshake. */
+void
+TorSocket::connectedToProxy()
+{
+ sendSocksHandshake(_remoteHost, _remotePort);
+}
+
/** Sends the first part of a Socks4a handshake, using the remote hostname and
* port specified in the previous call to connectToHost(). The message should
* be formatted as follows:
@@ -124,7 +126,7 @@
if ((uchar)response[0] == (uchar)SOCKS_RESPONSE_VERSION &&
(uchar)response[1] == (uchar)SOCKS_CONNECT_STATUS_OK) {
/* Connection status was okay. */
- emit connectedToHost();
+ emit connectedToRemoteHost();
} else {
/* Remote connection failed, so close the connection to the proxy. */
disconnectFromHost();
Modified: trunk/src/util/torsocket.h
===================================================================
--- trunk/src/util/torsocket.h 2007-12-01 03:55:42 UTC (rev 2147)
+++ trunk/src/util/torsocket.h 2007-12-01 07:39:48 UTC (rev 2148)
@@ -38,21 +38,23 @@
public:
/** Constructor. */
- TorSocket(QHostAddress socksAddr, quint16 socksPort, QObject *parent = 0);
+ TorSocket(const QHostAddress &socksAddr,
+ quint16 socksPort, QObject *parent = 0);
/** Connects to the specified hostname and port via Tor. */
- void connectToHost(const QString &remoteHost, quint16 remotePort);
+ void connectToRemoteHost(const QString &remoteHost, quint16 remotePort);
signals:
- /** Emitted when a connection has been established to Tor. */
- void connectedToTor();
/** Emitted when a connection has been established through Tor to the remote
* host specified in a prior call to connectToHost(). */
- void connectedToHost();
+ void connectedToRemoteHost();
/** Emmitted when a connection error has occurred. */
void socketError(QString errmsg);
private slots:
+ /** Called when the socket is connected to the proxy and sends our
+ * half of a Socks4a handshake. */
+ void connectedToProxy();
/** Handles the server's response part of a Socks4a handshake. */
void onHandshakeResponse();
/** Called when a connection error has occurred. */
@@ -63,7 +65,9 @@
void sendSocksHandshake(const QString &remoteHost, quint16 remotePort);
QHostAddress _socksAddr; /**< Address of Tor's SOCKS listener. */
+ QString _remoteHost; /**< Remote hostname. */
quint16 _socksPort; /**< Port of Tor's SOCKS listener. */
+ quint16 _remotePort; /**< Remote host port. */
};
#endif