libktorrent  2.2.0
socks.h
1 /***************************************************************************
2  * Copyright (C) 2007 by Joris Guisson and Ivan Vasic *
3  * joris.guisson@gmail.com *
4  * ivasic@gmail.com *
5  * *
6  * This program is free software; you can redistribute it and/or modify *
7  * it under the terms of the GNU General Public License as published by *
8  * the Free Software Foundation; either version 2 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * This program is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with this program; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20  ***************************************************************************/
21 #ifndef NETSOCKS_H
22 #define NETSOCKS_H
23 
24 #include <net/address.h>
25 #include <net/addressresolver.h>
26 #include <ktorrent_export.h>
27 #include <mse/encryptedpacketsocket.h>
28 
29 namespace net
30 {
36  class KTORRENT_EXPORT Socks : public QObject
37  {
38  Q_OBJECT
39  public:
40  enum State
41  {
42  IDLE,
43  CONNECTING_TO_SERVER,
44  CONNECTING_TO_HOST,
45  CONNECTED,
46  FAILED
47  };
48 
49  enum SetupState
50  {
51  NONE,
52  AUTH_REQUEST_SENT,
53  USERNAME_AND_PASSWORD_SENT,
54  CONNECT_REQUEST_SENT
55  };
56  Socks(mse::EncryptedPacketSocket::Ptr sock,const Address & dest);
57  ~Socks() override;
58 
60  State setup();
61 
66  State onReadyToWrite();
67 
72  State onReadyToRead();
73 
75  static bool enabled() {return socks_enabled;}
76 
78  static void setSocksEnabled(bool on) {socks_enabled = on;}
79 
81  static void setSocksServerAddress(const QString & host,bt::Uint16 port);
82 
84  static void setSocksVersion(int version) {socks_version = version;}
85 
91  static void setSocksAuthentication(const QString & username,const QString & password);
92 
93  private:
94  State sendAuthRequest();
95  void sendConnectRequest();
96  void sendUsernamePassword();
97  State handleAuthReply();
98  State handleUsernamePasswordReply();
99  State handleConnectReply();
100 
101  private Q_SLOTS:
102  void resolved(net::AddressResolver* ar);
103 
104  private:
105  mse::EncryptedPacketSocket::Ptr sock;
106  Address dest;
107  State state;
108  SetupState internal_state;
109  int version;
110 
111  static net::Address socks_server_addr;
112  static bool socks_server_addr_resolved;
113  static QString socks_server_host;
114  static bt::Uint16 socks_server_port;
115  static bool socks_enabled;
116  static int socks_version;
117  static QString socks_username;
118  static QString socks_password;
119  };
120 
121 }
122 
123 #endif
net::Socks::enabled
static bool enabled()
Is socks enabled.
Definition: socks.h:75
net::AddressResolver
Definition: addressresolver.h:37
net::Socks
Definition: socks.h:37
net::Socks::setSocksVersion
static void setSocksVersion(int version)
Set the socks version (4 or 5)
Definition: socks.h:84
net::Address
Definition: address.h:41
net::Socks::setSocksServerAddress
static void setSocksServerAddress(const QString &host, bt::Uint16 port)
Set the socks server address.
net::Socks::setSocksEnabled
static void setSocksEnabled(bool on)
Enable or disable socks.
Definition: socks.h:78
net::Socks::setup
State setup()
Setup a socks connection, return the current state.
net::Socks::onReadyToRead
State onReadyToRead()
net::Socks::onReadyToWrite
State onReadyToWrite()
net::Socks::setSocksAuthentication
static void setSocksAuthentication(const QString &username, const QString &password)