OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_BASE_SOCKS_CLIENT_SOCKET_H_ | 5 #ifndef NET_SOCKET_SOCKS_CLIENT_SOCKET_H_ |
6 #define NET_BASE_SOCKS_CLIENT_SOCKET_H_ | 6 #define NET_SOCKET_SOCKS_CLIENT_SOCKET_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
13 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
14 #include "net/base/address_list.h" | 14 #include "net/base/address_list.h" |
15 #include "net/base/completion_callback.h" | 15 #include "net/base/completion_callback.h" |
16 #include "net/base/host_resolver.h" | 16 #include "net/base/host_resolver.h" |
(...skipping 30 matching lines...) Expand all Loading... |
47 virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback); | 47 virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback); |
48 virtual int Write(IOBuffer* buf, int buf_len, CompletionCallback* callback); | 48 virtual int Write(IOBuffer* buf, int buf_len, CompletionCallback* callback); |
49 | 49 |
50 #if defined(OS_LINUX) | 50 #if defined(OS_LINUX) |
51 // Identical to posix system call getpeername(). | 51 // Identical to posix system call getpeername(). |
52 // Needed by ssl_client_socket_nss. | 52 // Needed by ssl_client_socket_nss. |
53 virtual int GetPeerName(struct sockaddr *name, socklen_t *namelen); | 53 virtual int GetPeerName(struct sockaddr *name, socklen_t *namelen); |
54 #endif | 54 #endif |
55 | 55 |
56 private: | 56 private: |
| 57 FRIEND_TEST(SOCKSClientSocketTest, CompleteHandshake); |
| 58 FRIEND_TEST(SOCKSClientSocketTest, SOCKS4AFailedDNS); |
| 59 FRIEND_TEST(SOCKSClientSocketTest, SOCKS4AIfDomainInIPv6); |
| 60 |
57 enum State { | 61 enum State { |
58 STATE_RESOLVE_HOST, | 62 STATE_RESOLVE_HOST, |
59 STATE_RESOLVE_HOST_COMPLETE, | 63 STATE_RESOLVE_HOST_COMPLETE, |
60 STATE_HANDSHAKE_WRITE, | 64 STATE_HANDSHAKE_WRITE, |
61 STATE_HANDSHAKE_WRITE_COMPLETE, | 65 STATE_HANDSHAKE_WRITE_COMPLETE, |
62 STATE_HANDSHAKE_READ, | 66 STATE_HANDSHAKE_READ, |
63 STATE_HANDSHAKE_READ_COMPLETE, | 67 STATE_HANDSHAKE_READ_COMPLETE, |
64 STATE_NONE, | 68 STATE_NONE, |
65 }; | 69 }; |
66 | 70 |
(...skipping 11 matching lines...) Expand all Loading... |
78 void OnIOComplete(int result); | 82 void OnIOComplete(int result); |
79 | 83 |
80 int DoLoop(int last_io_result); | 84 int DoLoop(int last_io_result); |
81 int DoResolveHost(); | 85 int DoResolveHost(); |
82 int DoResolveHostComplete(int result); | 86 int DoResolveHostComplete(int result); |
83 int DoHandshakeRead(); | 87 int DoHandshakeRead(); |
84 int DoHandshakeReadComplete(int result); | 88 int DoHandshakeReadComplete(int result); |
85 int DoHandshakeWrite(); | 89 int DoHandshakeWrite(); |
86 int DoHandshakeWriteComplete(int result); | 90 int DoHandshakeWriteComplete(int result); |
87 | 91 |
88 void BuildHandshakeWriteBuffer(); | 92 const std::string BuildHandshakeWriteBuffer() const; |
89 | 93 |
90 CompletionCallbackImpl<SOCKSClientSocket> io_callback_; | 94 CompletionCallbackImpl<SOCKSClientSocket> io_callback_; |
91 | 95 |
92 // Stores the underlying socket. | 96 // Stores the underlying socket. |
93 scoped_ptr<ClientSocket> transport_; | 97 scoped_ptr<ClientSocket> transport_; |
94 | 98 |
95 State next_state_; | 99 State next_state_; |
96 SocksVersion socks_version_; | 100 SocksVersion socks_version_; |
97 | 101 |
98 // Stores the callback to the layer above, called on completing Connect(). | 102 // Stores the callback to the layer above, called on completing Connect(). |
99 CompletionCallback* user_callback_; | 103 CompletionCallback* user_callback_; |
100 | 104 |
101 // This IOBuffer is used by the class to read and write | 105 // This IOBuffer is used by the class to read and write |
102 // SOCKS handshake data. The length contains the expected size to | 106 // SOCKS handshake data. The length contains the expected size to |
103 // read or write. | 107 // read or write. |
104 scoped_refptr<IOBuffer> handshake_buf_; | 108 scoped_refptr<IOBuffer> handshake_buf_; |
105 int handshake_buf_len_; | |
106 | 109 |
107 // While writing, this buffer stores the complete write handshake data. | 110 // While writing, this buffer stores the complete write handshake data. |
108 // While reading, it stores the handshake information received so far. | 111 // While reading, it stores the handshake information received so far. |
109 scoped_array<char> buffer_; | 112 std::string buffer_; |
110 int buffer_len_; | |
111 | 113 |
112 // This becomes true when the SOCKS handshake has completed and the | 114 // This becomes true when the SOCKS handshake has completed and the |
113 // overlying connection is free to communicate. | 115 // overlying connection is free to communicate. |
114 bool completed_handshake_; | 116 bool completed_handshake_; |
115 | 117 |
116 // These contain the bytes sent / received by the SOCKS handshake. | 118 // These contain the bytes sent / received by the SOCKS handshake. |
117 int bytes_sent_; | 119 size_t bytes_sent_; |
118 int bytes_received_; | 120 size_t bytes_received_; |
119 | 121 |
120 // Used to resolve the hostname to which the SOCKS proxy will connect. | 122 // Used to resolve the hostname to which the SOCKS proxy will connect. |
121 SingleRequestHostResolver resolver_; | 123 SingleRequestHostResolver host_resolver_; |
122 AddressList addresses_; | 124 AddressList addresses_; |
123 HostResolver::RequestInfo host_request_info_; | 125 HostResolver::RequestInfo host_request_info_; |
124 | 126 |
125 DISALLOW_COPY_AND_ASSIGN(SOCKSClientSocket); | 127 DISALLOW_COPY_AND_ASSIGN(SOCKSClientSocket); |
126 }; | 128 }; |
127 | 129 |
128 } // namespace net | 130 } // namespace net |
129 | 131 |
130 #endif // NET_BASE_SOCKS_CLIENT_SOCKET_H_ | 132 #endif // NET_SOCKET_SOCKS_CLIENT_SOCKET_H_ |
131 | 133 |
OLD | NEW |