Vidalia
0.2.15
|
00001 /* 00002 ** This file is part of Vidalia, and is subject to the license terms in the 00003 ** LICENSE file, found in the top level directory of this distribution. If you 00004 ** did not receive the LICENSE file with this file, you may obtain it from the 00005 ** Vidalia source package distributed by the Vidalia Project at 00006 ** http://www.torproject.org/projects/vidalia.html. No part of Vidalia, 00007 ** including this file, may be copied, modified, propagated, or distributed 00008 ** except according to the terms described in the LICENSE file. 00009 */ 00010 00011 /* 00012 ** \file TorSocket.h 00013 ** \brief A QTcpSocket that makes requests over Tor 00014 */ 00015 00016 #ifndef _TORSOCKET_H 00017 #define _TORSOCKET_H 00018 00019 #include <QTcpSocket> 00020 #include <QHostAddress> 00021 00022 00023 class TorSocket : public QTcpSocket 00024 { 00025 Q_OBJECT 00026 00027 public: 00028 /** Constructor. */ 00029 TorSocket(const QHostAddress &socksAddr, 00030 quint16 socksPort, QObject *parent = 0); 00031 00032 /** Connects to the specified hostname and port via Tor. */ 00033 void connectToRemoteHost(const QString &remoteHost, quint16 remotePort); 00034 00035 signals: 00036 /** Emitted when a connection has been established through Tor to the remote 00037 * host specified in a prior call to connectToHost(). */ 00038 void connectedToRemoteHost(); 00039 /** Emitted when a connection error has occurred. */ 00040 void socketError(QString errmsg); 00041 00042 private slots: 00043 /** Called when the socket is connected to the proxy and sends our 00044 * half of a Socks4a handshake. */ 00045 void connectedToProxy(); 00046 /** Handles the server's response part of a Socks4a handshake. */ 00047 void onHandshakeResponse(); 00048 /** Called when a connection error has occurred. */ 00049 void onError(QAbstractSocket::SocketError error); 00050 00051 private: 00052 /** Sends the client part of a Socks4a handshake with a proxy server. */ 00053 void sendSocksHandshake(const QString &remoteHost, quint16 remotePort); 00054 00055 QHostAddress _socksAddr; /**< Address of Tor's SOCKS listener. */ 00056 QString _remoteHost; /**< Remote hostname. */ 00057 quint16 _socksPort; /**< Port of Tor's SOCKS listener. */ 00058 quint16 _remotePort; /**< Remote host port. */ 00059 }; 00060 00061 #endif 00062