| 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 #include "net/socket/socks5_client_socket.h" | 5 #include "net/socket/socks5_client_socket.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/trace_event.h" | 11 #include "base/trace_event.h" |
| 12 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
| 13 #include "net/base/load_log.h" | 13 #include "net/base/net_log.h" |
| 14 #include "net/base/net_util.h" | 14 #include "net/base/net_util.h" |
| 15 #include "net/base/sys_addrinfo.h" | 15 #include "net/base/sys_addrinfo.h" |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 // Returns a string description of |socks_error|, or NULL if |socks_error| is | 21 // Returns a string description of |socks_error|, or NULL if |socks_error| is |
| 22 // not a valid SOCKS reply. | 22 // not a valid SOCKS reply. |
| 23 const char* MapSOCKSReplyToErrorString(char socks_error) { | 23 const char* MapSOCKSReplyToErrorString(char socks_error) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 bytes_received_(0), | 58 bytes_received_(0), |
| 59 read_header_size(kReadHeaderSize), | 59 read_header_size(kReadHeaderSize), |
| 60 host_request_info_(req_info) { | 60 host_request_info_(req_info) { |
| 61 } | 61 } |
| 62 | 62 |
| 63 SOCKS5ClientSocket::~SOCKS5ClientSocket() { | 63 SOCKS5ClientSocket::~SOCKS5ClientSocket() { |
| 64 Disconnect(); | 64 Disconnect(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 int SOCKS5ClientSocket::Connect(CompletionCallback* callback, | 67 int SOCKS5ClientSocket::Connect(CompletionCallback* callback, |
| 68 LoadLog* load_log) { | 68 const BoundNetLog& net_log) { |
| 69 DCHECK(transport_.get()); | 69 DCHECK(transport_.get()); |
| 70 DCHECK(transport_->IsConnected()); | 70 DCHECK(transport_->IsConnected()); |
| 71 DCHECK_EQ(STATE_NONE, next_state_); | 71 DCHECK_EQ(STATE_NONE, next_state_); |
| 72 DCHECK(!user_callback_); | 72 DCHECK(!user_callback_); |
| 73 | 73 |
| 74 // If already connected, then just return OK. | 74 // If already connected, then just return OK. |
| 75 if (completed_handshake_) | 75 if (completed_handshake_) |
| 76 return OK; | 76 return OK; |
| 77 | 77 |
| 78 load_log_ = load_log; | 78 net_log_ = net_log; |
| 79 LoadLog::BeginEvent(load_log, LoadLog::TYPE_SOCKS5_CONNECT); | 79 net_log.BeginEvent(NetLog::TYPE_SOCKS5_CONNECT); |
| 80 | 80 |
| 81 next_state_ = STATE_GREET_WRITE; | 81 next_state_ = STATE_GREET_WRITE; |
| 82 buffer_.clear(); | 82 buffer_.clear(); |
| 83 | 83 |
| 84 int rv = DoLoop(OK); | 84 int rv = DoLoop(OK); |
| 85 if (rv == ERR_IO_PENDING) { | 85 if (rv == ERR_IO_PENDING) { |
| 86 user_callback_ = callback; | 86 user_callback_ = callback; |
| 87 } else { | 87 } else { |
| 88 LoadLog::EndEvent(load_log, LoadLog::TYPE_SOCKS5_CONNECT); | 88 net_log.EndEvent(NetLog::TYPE_SOCKS5_CONNECT); |
| 89 load_log_ = NULL; | 89 net_log_ = BoundNetLog(); |
| 90 } | 90 } |
| 91 return rv; | 91 return rv; |
| 92 } | 92 } |
| 93 | 93 |
| 94 void SOCKS5ClientSocket::Disconnect() { | 94 void SOCKS5ClientSocket::Disconnect() { |
| 95 completed_handshake_ = false; | 95 completed_handshake_ = false; |
| 96 transport_->Disconnect(); | 96 transport_->Disconnect(); |
| 97 | 97 |
| 98 // Reset other states to make sure they aren't mistakenly used later. | 98 // Reset other states to make sure they aren't mistakenly used later. |
| 99 // These are the states initialized by Connect(). | 99 // These are the states initialized by Connect(). |
| 100 next_state_ = STATE_NONE; | 100 next_state_ = STATE_NONE; |
| 101 user_callback_ = NULL; | 101 user_callback_ = NULL; |
| 102 load_log_ = NULL; | 102 net_log_ = BoundNetLog(); |
| 103 } | 103 } |
| 104 | 104 |
| 105 bool SOCKS5ClientSocket::IsConnected() const { | 105 bool SOCKS5ClientSocket::IsConnected() const { |
| 106 return completed_handshake_ && transport_->IsConnected(); | 106 return completed_handshake_ && transport_->IsConnected(); |
| 107 } | 107 } |
| 108 | 108 |
| 109 bool SOCKS5ClientSocket::IsConnectedAndIdle() const { | 109 bool SOCKS5ClientSocket::IsConnectedAndIdle() const { |
| 110 return completed_handshake_ && transport_->IsConnectedAndIdle(); | 110 return completed_handshake_ && transport_->IsConnectedAndIdle(); |
| 111 } | 111 } |
| 112 | 112 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 // clear user_callback_ up front. | 148 // clear user_callback_ up front. |
| 149 CompletionCallback* c = user_callback_; | 149 CompletionCallback* c = user_callback_; |
| 150 user_callback_ = NULL; | 150 user_callback_ = NULL; |
| 151 c->Run(result); | 151 c->Run(result); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void SOCKS5ClientSocket::OnIOComplete(int result) { | 154 void SOCKS5ClientSocket::OnIOComplete(int result) { |
| 155 DCHECK_NE(STATE_NONE, next_state_); | 155 DCHECK_NE(STATE_NONE, next_state_); |
| 156 int rv = DoLoop(result); | 156 int rv = DoLoop(result); |
| 157 if (rv != ERR_IO_PENDING) { | 157 if (rv != ERR_IO_PENDING) { |
| 158 LoadLog::EndEvent(load_log_, LoadLog::TYPE_SOCKS5_CONNECT); | 158 net_log_.EndEvent(NetLog::TYPE_SOCKS5_CONNECT); |
| 159 load_log_ = NULL; | 159 net_log_ = BoundNetLog(); |
| 160 DoCallback(rv); | 160 DoCallback(rv); |
| 161 } | 161 } |
| 162 } | 162 } |
| 163 | 163 |
| 164 int SOCKS5ClientSocket::DoLoop(int last_io_result) { | 164 int SOCKS5ClientSocket::DoLoop(int last_io_result) { |
| 165 DCHECK_NE(next_state_, STATE_NONE); | 165 DCHECK_NE(next_state_, STATE_NONE); |
| 166 int rv = last_io_result; | 166 int rv = last_io_result; |
| 167 do { | 167 do { |
| 168 State state = next_state_; | 168 State state = next_state_; |
| 169 next_state_ = STATE_NONE; | 169 next_state_ = STATE_NONE; |
| 170 switch (state) { | 170 switch (state) { |
| 171 case STATE_GREET_WRITE: | 171 case STATE_GREET_WRITE: |
| 172 DCHECK_EQ(OK, rv); | 172 DCHECK_EQ(OK, rv); |
| 173 LoadLog::BeginEvent(load_log_, LoadLog::TYPE_SOCKS5_GREET_WRITE); | 173 net_log_.BeginEvent(NetLog::TYPE_SOCKS5_GREET_WRITE); |
| 174 rv = DoGreetWrite(); | 174 rv = DoGreetWrite(); |
| 175 break; | 175 break; |
| 176 case STATE_GREET_WRITE_COMPLETE: | 176 case STATE_GREET_WRITE_COMPLETE: |
| 177 rv = DoGreetWriteComplete(rv); | 177 rv = DoGreetWriteComplete(rv); |
| 178 LoadLog::EndEvent(load_log_, LoadLog::TYPE_SOCKS5_GREET_WRITE); | 178 net_log_.EndEvent(NetLog::TYPE_SOCKS5_GREET_WRITE); |
| 179 break; | 179 break; |
| 180 case STATE_GREET_READ: | 180 case STATE_GREET_READ: |
| 181 DCHECK_EQ(OK, rv); | 181 DCHECK_EQ(OK, rv); |
| 182 LoadLog::BeginEvent(load_log_, LoadLog::TYPE_SOCKS5_GREET_READ); | 182 net_log_.BeginEvent(NetLog::TYPE_SOCKS5_GREET_READ); |
| 183 rv = DoGreetRead(); | 183 rv = DoGreetRead(); |
| 184 break; | 184 break; |
| 185 case STATE_GREET_READ_COMPLETE: | 185 case STATE_GREET_READ_COMPLETE: |
| 186 rv = DoGreetReadComplete(rv); | 186 rv = DoGreetReadComplete(rv); |
| 187 LoadLog::EndEvent(load_log_, LoadLog::TYPE_SOCKS5_GREET_READ); | 187 net_log_.EndEvent(NetLog::TYPE_SOCKS5_GREET_READ); |
| 188 break; | 188 break; |
| 189 case STATE_HANDSHAKE_WRITE: | 189 case STATE_HANDSHAKE_WRITE: |
| 190 DCHECK_EQ(OK, rv); | 190 DCHECK_EQ(OK, rv); |
| 191 LoadLog::BeginEvent(load_log_, LoadLog::TYPE_SOCKS5_HANDSHAKE_WRITE); | 191 net_log_.BeginEvent(NetLog::TYPE_SOCKS5_HANDSHAKE_WRITE); |
| 192 rv = DoHandshakeWrite(); | 192 rv = DoHandshakeWrite(); |
| 193 break; | 193 break; |
| 194 case STATE_HANDSHAKE_WRITE_COMPLETE: | 194 case STATE_HANDSHAKE_WRITE_COMPLETE: |
| 195 rv = DoHandshakeWriteComplete(rv); | 195 rv = DoHandshakeWriteComplete(rv); |
| 196 LoadLog::EndEvent(load_log_, LoadLog::TYPE_SOCKS5_HANDSHAKE_WRITE); | 196 net_log_.EndEvent(NetLog::TYPE_SOCKS5_HANDSHAKE_WRITE); |
| 197 break; | 197 break; |
| 198 case STATE_HANDSHAKE_READ: | 198 case STATE_HANDSHAKE_READ: |
| 199 DCHECK_EQ(OK, rv); | 199 DCHECK_EQ(OK, rv); |
| 200 LoadLog::BeginEvent(load_log_, LoadLog::TYPE_SOCKS5_HANDSHAKE_READ); | 200 net_log_.BeginEvent(NetLog::TYPE_SOCKS5_HANDSHAKE_READ); |
| 201 rv = DoHandshakeRead(); | 201 rv = DoHandshakeRead(); |
| 202 break; | 202 break; |
| 203 case STATE_HANDSHAKE_READ_COMPLETE: | 203 case STATE_HANDSHAKE_READ_COMPLETE: |
| 204 rv = DoHandshakeReadComplete(rv); | 204 rv = DoHandshakeReadComplete(rv); |
| 205 LoadLog::EndEvent(load_log_, LoadLog::TYPE_SOCKS5_HANDSHAKE_READ); | 205 net_log_.EndEvent(NetLog::TYPE_SOCKS5_HANDSHAKE_READ); |
| 206 break; | 206 break; |
| 207 default: | 207 default: |
| 208 NOTREACHED() << "bad state"; | 208 NOTREACHED() << "bad state"; |
| 209 rv = ERR_UNEXPECTED; | 209 rv = ERR_UNEXPECTED; |
| 210 break; | 210 break; |
| 211 } | 211 } |
| 212 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); | 212 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); |
| 213 return rv; | 213 return rv; |
| 214 } | 214 } |
| 215 | 215 |
| 216 const char kSOCKS5GreetWriteData[] = { 0x05, 0x01, 0x00 }; // no authentication | 216 const char kSOCKS5GreetWriteData[] = { 0x05, 0x01, 0x00 }; // no authentication |
| 217 const char kSOCKS5GreetReadData[] = { 0x05, 0x00 }; | 217 const char kSOCKS5GreetReadData[] = { 0x05, 0x00 }; |
| 218 | 218 |
| 219 int SOCKS5ClientSocket::DoGreetWrite() { | 219 int SOCKS5ClientSocket::DoGreetWrite() { |
| 220 // Since we only have 1 byte to send the hostname length in, if the | 220 // Since we only have 1 byte to send the hostname length in, if the |
| 221 // URL has a hostname longer than 255 characters we can't send it. | 221 // URL has a hostname longer than 255 characters we can't send it. |
| 222 if (0xFF < host_request_info_.hostname().size()) { | 222 if (0xFF < host_request_info_.hostname().size()) { |
| 223 LoadLog::AddStringLiteral(load_log_, | 223 net_log_.AddStringLiteral("Failed sending request because hostname is " |
| 224 "Failed sending request because hostname is " | |
| 225 "longer than 255 characters"); | 224 "longer than 255 characters"); |
| 226 return ERR_SOCKS_CONNECTION_FAILED; | 225 return ERR_SOCKS_CONNECTION_FAILED; |
| 227 } | 226 } |
| 228 | 227 |
| 229 if (buffer_.empty()) { | 228 if (buffer_.empty()) { |
| 230 buffer_ = std::string(kSOCKS5GreetWriteData, | 229 buffer_ = std::string(kSOCKS5GreetWriteData, |
| 231 arraysize(kSOCKS5GreetWriteData)); | 230 arraysize(kSOCKS5GreetWriteData)); |
| 232 bytes_sent_ = 0; | 231 bytes_sent_ = 0; |
| 233 } | 232 } |
| 234 | 233 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 260 size_t handshake_buf_len = kGreetReadHeaderSize - bytes_received_; | 259 size_t handshake_buf_len = kGreetReadHeaderSize - bytes_received_; |
| 261 handshake_buf_ = new IOBuffer(handshake_buf_len); | 260 handshake_buf_ = new IOBuffer(handshake_buf_len); |
| 262 return transport_->Read(handshake_buf_, handshake_buf_len, &io_callback_); | 261 return transport_->Read(handshake_buf_, handshake_buf_len, &io_callback_); |
| 263 } | 262 } |
| 264 | 263 |
| 265 int SOCKS5ClientSocket::DoGreetReadComplete(int result) { | 264 int SOCKS5ClientSocket::DoGreetReadComplete(int result) { |
| 266 if (result < 0) | 265 if (result < 0) |
| 267 return result; | 266 return result; |
| 268 | 267 |
| 269 if (result == 0) { | 268 if (result == 0) { |
| 270 LoadLog::AddStringLiteral( | 269 net_log_.AddStringLiteral( |
| 271 load_log_, "Connection unexpected closed while reading greeting."); | 270 "Connection unexpected closed while reading greeting."); |
| 272 return ERR_SOCKS_CONNECTION_FAILED; | 271 return ERR_SOCKS_CONNECTION_FAILED; |
| 273 } | 272 } |
| 274 | 273 |
| 275 bytes_received_ += result; | 274 bytes_received_ += result; |
| 276 buffer_.append(handshake_buf_->data(), result); | 275 buffer_.append(handshake_buf_->data(), result); |
| 277 if (bytes_received_ < kGreetReadHeaderSize) { | 276 if (bytes_received_ < kGreetReadHeaderSize) { |
| 278 next_state_ = STATE_GREET_READ; | 277 next_state_ = STATE_GREET_READ; |
| 279 return OK; | 278 return OK; |
| 280 } | 279 } |
| 281 | 280 |
| 282 // Got the greet data. | 281 // Got the greet data. |
| 283 if (buffer_[0] != kSOCKS5Version) { | 282 if (buffer_[0] != kSOCKS5Version) { |
| 284 LoadLog::AddStringLiteral(load_log_, "Unexpected SOCKS version"); | 283 net_log_.AddStringLiteral("Unexpected SOCKS version"); |
| 285 LoadLog::AddString(load_log_, StringPrintf( | 284 net_log_.AddString(StringPrintf( |
| 286 "buffer_[0] = 0x%x", static_cast<int>(buffer_[0]))); | 285 "buffer_[0] = 0x%x", static_cast<int>(buffer_[0]))); |
| 287 return ERR_SOCKS_CONNECTION_FAILED; | 286 return ERR_SOCKS_CONNECTION_FAILED; |
| 288 } | 287 } |
| 289 if (buffer_[1] != 0x00) { | 288 if (buffer_[1] != 0x00) { |
| 290 LoadLog::AddStringLiteral(load_log_, "Unexpected authentication method"); | 289 net_log_.AddStringLiteral("Unexpected authentication method"); |
| 291 LoadLog::AddString(load_log_, StringPrintf( | 290 net_log_.AddString(StringPrintf( |
| 292 "buffer_[1] = 0x%x", static_cast<int>(buffer_[1]))); | 291 "buffer_[1] = 0x%x", static_cast<int>(buffer_[1]))); |
| 293 return ERR_SOCKS_CONNECTION_FAILED; | 292 return ERR_SOCKS_CONNECTION_FAILED; |
| 294 } | 293 } |
| 295 | 294 |
| 296 buffer_.clear(); | 295 buffer_.clear(); |
| 297 next_state_ = STATE_HANDSHAKE_WRITE; | 296 next_state_ = STATE_HANDSHAKE_WRITE; |
| 298 return OK; | 297 return OK; |
| 299 } | 298 } |
| 300 | 299 |
| 301 int SOCKS5ClientSocket::BuildHandshakeWriteBuffer(std::string* handshake) | 300 int SOCKS5ClientSocket::BuildHandshakeWriteBuffer(std::string* handshake) |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 handshake_buf_ = new IOBuffer(handshake_buf_len); | 370 handshake_buf_ = new IOBuffer(handshake_buf_len); |
| 372 return transport_->Read(handshake_buf_, handshake_buf_len, &io_callback_); | 371 return transport_->Read(handshake_buf_, handshake_buf_len, &io_callback_); |
| 373 } | 372 } |
| 374 | 373 |
| 375 int SOCKS5ClientSocket::DoHandshakeReadComplete(int result) { | 374 int SOCKS5ClientSocket::DoHandshakeReadComplete(int result) { |
| 376 if (result < 0) | 375 if (result < 0) |
| 377 return result; | 376 return result; |
| 378 | 377 |
| 379 // The underlying socket closed unexpectedly. | 378 // The underlying socket closed unexpectedly. |
| 380 if (result == 0) { | 379 if (result == 0) { |
| 381 LoadLog::AddStringLiteral( | 380 net_log_.AddStringLiteral( |
| 382 load_log_, "Connection unexpected closed while reading handshake."); | 381 "Connection unexpected closed while reading handshake."); |
| 383 return ERR_SOCKS_CONNECTION_FAILED; | 382 return ERR_SOCKS_CONNECTION_FAILED; |
| 384 } | 383 } |
| 385 | 384 |
| 386 buffer_.append(handshake_buf_->data(), result); | 385 buffer_.append(handshake_buf_->data(), result); |
| 387 bytes_received_ += result; | 386 bytes_received_ += result; |
| 388 | 387 |
| 389 // When the first few bytes are read, check how many more are required | 388 // When the first few bytes are read, check how many more are required |
| 390 // and accordingly increase them | 389 // and accordingly increase them |
| 391 if (bytes_received_ == kReadHeaderSize) { | 390 if (bytes_received_ == kReadHeaderSize) { |
| 392 if (buffer_[0] != kSOCKS5Version || buffer_[2] != kNullByte) { | 391 if (buffer_[0] != kSOCKS5Version || buffer_[2] != kNullByte) { |
| 393 LoadLog::AddStringLiteral(load_log_, "Unexpected SOCKS version."); | 392 net_log_.AddStringLiteral("Unexpected SOCKS version."); |
| 394 LoadLog::AddString(load_log_, StringPrintf( | 393 net_log_.AddString(StringPrintf( |
| 395 "buffer_[0] = 0x%x; buffer_[2] = 0x%x", | 394 "buffer_[0] = 0x%x; buffer_[2] = 0x%x", |
| 396 static_cast<int>(buffer_[0]), | 395 static_cast<int>(buffer_[0]), |
| 397 static_cast<int>(buffer_[2]))); | 396 static_cast<int>(buffer_[2]))); |
| 398 return ERR_SOCKS_CONNECTION_FAILED; | 397 return ERR_SOCKS_CONNECTION_FAILED; |
| 399 } | 398 } |
| 400 if (buffer_[1] != 0x00) { | 399 if (buffer_[1] != 0x00) { |
| 401 LoadLog::AddStringLiteral(load_log_, | 400 net_log_.AddStringLiteral("SOCKS server returned a failure code:"); |
| 402 "SOCKS server returned a failure code:"); | |
| 403 const char* error_string = MapSOCKSReplyToErrorString(buffer_[1]); | 401 const char* error_string = MapSOCKSReplyToErrorString(buffer_[1]); |
| 404 if (error_string) { | 402 if (error_string) { |
| 405 LoadLog::AddStringLiteral(load_log_, error_string); | 403 net_log_.AddStringLiteral(error_string); |
| 406 } else { | 404 } else { |
| 407 LoadLog::AddString(load_log_, StringPrintf( | 405 net_log_.AddString(StringPrintf( |
| 408 "buffer_[1] = 0x%x", static_cast<int>(buffer_[1]))); | 406 "buffer_[1] = 0x%x", static_cast<int>(buffer_[1]))); |
| 409 } | 407 } |
| 410 return ERR_SOCKS_CONNECTION_FAILED; | 408 return ERR_SOCKS_CONNECTION_FAILED; |
| 411 } | 409 } |
| 412 | 410 |
| 413 // We check the type of IP/Domain the server returns and accordingly | 411 // We check the type of IP/Domain the server returns and accordingly |
| 414 // increase the size of the response. For domains, we need to read the | 412 // increase the size of the response. For domains, we need to read the |
| 415 // size of the domain, so the initial request size is upto the domain | 413 // size of the domain, so the initial request size is upto the domain |
| 416 // size. Since for IPv4/IPv6 the size is fixed and hence no 'size' is | 414 // size. Since for IPv4/IPv6 the size is fixed and hence no 'size' is |
| 417 // read, we substract 1 byte from the additional request size. | 415 // read, we substract 1 byte from the additional request size. |
| 418 SocksEndPointAddressType address_type = | 416 SocksEndPointAddressType address_type = |
| 419 static_cast<SocksEndPointAddressType>(buffer_[3]); | 417 static_cast<SocksEndPointAddressType>(buffer_[3]); |
| 420 if (address_type == kEndPointDomain) | 418 if (address_type == kEndPointDomain) |
| 421 read_header_size += static_cast<uint8>(buffer_[4]); | 419 read_header_size += static_cast<uint8>(buffer_[4]); |
| 422 else if (address_type == kEndPointResolvedIPv4) | 420 else if (address_type == kEndPointResolvedIPv4) |
| 423 read_header_size += sizeof(struct in_addr) - 1; | 421 read_header_size += sizeof(struct in_addr) - 1; |
| 424 else if (address_type == kEndPointResolvedIPv6) | 422 else if (address_type == kEndPointResolvedIPv6) |
| 425 read_header_size += sizeof(struct in6_addr) - 1; | 423 read_header_size += sizeof(struct in6_addr) - 1; |
| 426 else { | 424 else { |
| 427 LoadLog::AddStringLiteral(load_log_, "Unknown address type in response"); | 425 net_log_.AddStringLiteral("Unknown address type in response"); |
| 428 LoadLog::AddString(load_log_, StringPrintf( | 426 net_log_.AddString(StringPrintf( |
| 429 "buffer_[3] = 0x%x", static_cast<int>(buffer_[3]))); | 427 "buffer_[3] = 0x%x", static_cast<int>(buffer_[3]))); |
| 430 return ERR_SOCKS_CONNECTION_FAILED; | 428 return ERR_SOCKS_CONNECTION_FAILED; |
| 431 } | 429 } |
| 432 | 430 |
| 433 read_header_size += 2; // for the port. | 431 read_header_size += 2; // for the port. |
| 434 next_state_ = STATE_HANDSHAKE_READ; | 432 next_state_ = STATE_HANDSHAKE_READ; |
| 435 return OK; | 433 return OK; |
| 436 } | 434 } |
| 437 | 435 |
| 438 // When the final bytes are read, setup handshake. We ignore the rest | 436 // When the final bytes are read, setup handshake. We ignore the rest |
| 439 // of the response since they represent the SOCKSv5 endpoint and have | 437 // of the response since they represent the SOCKSv5 endpoint and have |
| 440 // no use when doing a tunnel connection. | 438 // no use when doing a tunnel connection. |
| 441 if (bytes_received_ == read_header_size) { | 439 if (bytes_received_ == read_header_size) { |
| 442 completed_handshake_ = true; | 440 completed_handshake_ = true; |
| 443 buffer_.clear(); | 441 buffer_.clear(); |
| 444 next_state_ = STATE_NONE; | 442 next_state_ = STATE_NONE; |
| 445 return OK; | 443 return OK; |
| 446 } | 444 } |
| 447 | 445 |
| 448 next_state_ = STATE_HANDSHAKE_READ; | 446 next_state_ = STATE_HANDSHAKE_READ; |
| 449 return OK; | 447 return OK; |
| 450 } | 448 } |
| 451 | 449 |
| 452 int SOCKS5ClientSocket::GetPeerAddress(AddressList* address) const { | 450 int SOCKS5ClientSocket::GetPeerAddress(AddressList* address) const { |
| 453 return transport_->GetPeerAddress(address); | 451 return transport_->GetPeerAddress(address); |
| 454 } | 452 } |
| 455 | 453 |
| 456 } // namespace net | 454 } // namespace net |
| OLD | NEW |