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.vidalia-project.net/. No part of Vidalia, including this file, 00007 ** may be copied, modified, propagated, or distributed except according to the 00008 ** terms described in the LICENSE file. 00009 */ 00010 00011 /* 00012 ** \file torsocket.h 00013 ** \version $Id: torsocket.h 2362 2008-02-29 04:30:11Z edmanm $ 00014 ** \brief A QTcpSocket that makes requests over Tor 00015 */ 00016 00017 #ifndef _TORSOCKET_H 00018 #define _TORSOCKET_H 00019 00020 #include <QTcpSocket> 00021 #include <QHostAddress> 00022 00023 00024 class TorSocket : public QTcpSocket 00025 { 00026 Q_OBJECT 00027 00028 public: 00029 /** Constructor. */ 00030 TorSocket(const QHostAddress &socksAddr, 00031 quint16 socksPort, QObject *parent = 0); 00032 00033 /** Connects to the specified hostname and port via Tor. */ 00034 void connectToRemoteHost(const QString &remoteHost, quint16 remotePort); 00035 00036 signals: 00037 /** Emitted when a connection has been established through Tor to the remote 00038 * host specified in a prior call to connectToHost(). */ 00039 void connectedToRemoteHost(); 00040 /** Emitted when a connection error has occurred. */ 00041 void socketError(QString errmsg); 00042 00043 private slots: 00044 /** Called when the socket is connected to the proxy and sends our 00045 * half of a Socks4a handshake. */ 00046 void connectedToProxy(); 00047 /** Handles the server's response part of a Socks4a handshake. */ 00048 void onHandshakeResponse(); 00049 /** Called when a connection error has occurred. */ 00050 void onError(QAbstractSocket::SocketError error); 00051 00052 private: 00053 /** Sends the client part of a Socks4a handshake with a proxy server. */ 00054 void sendSocksHandshake(const QString &remoteHost, quint16 remotePort); 00055 00056 QHostAddress _socksAddr; /**< Address of Tor's SOCKS listener. */ 00057 QString _remoteHost; /**< Remote hostname. */ 00058 quint16 _socksPort; /**< Port of Tor's SOCKS listener. */ 00059 quint16 _remotePort; /**< Remote host port. */ 00060 }; 00061 00062 #endif 00063