Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Side by Side Diff: net/socket/socks5_client_socket.cc

Issue 507033: When talking to a SOCKS v5 proxy, default to sending addresses as raw domains... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Address wtc's comments Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/trace_event.h" 9 #include "base/trace_event.h"
10 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
(...skipping 19 matching lines...) Expand all
30 : ALLOW_THIS_IN_INITIALIZER_LIST( 30 : ALLOW_THIS_IN_INITIALIZER_LIST(
31 io_callback_(this, &SOCKS5ClientSocket::OnIOComplete)), 31 io_callback_(this, &SOCKS5ClientSocket::OnIOComplete)),
32 transport_(transport_socket), 32 transport_(transport_socket),
33 next_state_(STATE_NONE), 33 next_state_(STATE_NONE),
34 address_type_(kEndPointUnresolved), 34 address_type_(kEndPointUnresolved),
35 user_callback_(NULL), 35 user_callback_(NULL),
36 completed_handshake_(false), 36 completed_handshake_(false),
37 bytes_sent_(0), 37 bytes_sent_(0),
38 bytes_received_(0), 38 bytes_received_(0),
39 read_header_size(kReadHeaderSize), 39 read_header_size(kReadHeaderSize),
40 host_resolver_(host_resolver),
41 host_request_info_(req_info) { 40 host_request_info_(req_info) {
41 if (host_resolver)
42 host_resolver_.reset(new SingleRequestHostResolver(host_resolver));
42 } 43 }
43 44
44 SOCKS5ClientSocket::~SOCKS5ClientSocket() { 45 SOCKS5ClientSocket::~SOCKS5ClientSocket() {
45 Disconnect(); 46 Disconnect();
46 } 47 }
47 48
48 int SOCKS5ClientSocket::Connect(CompletionCallback* callback, 49 int SOCKS5ClientSocket::Connect(CompletionCallback* callback,
49 LoadLog* load_log) { 50 LoadLog* load_log) {
50 DCHECK(transport_.get()); 51 DCHECK(transport_.get());
51 DCHECK(transport_->IsConnected()); 52 DCHECK(transport_->IsConnected());
52 DCHECK_EQ(STATE_NONE, next_state_); 53 DCHECK_EQ(STATE_NONE, next_state_);
53 DCHECK(!user_callback_); 54 DCHECK(!user_callback_);
54 55
55 // If already connected, then just return OK. 56 // If already connected, then just return OK.
56 if (completed_handshake_) 57 if (completed_handshake_)
57 return OK; 58 return OK;
58 59
59 next_state_ = STATE_RESOLVE_HOST;
60 load_log_ = load_log; 60 load_log_ = load_log;
61 LoadLog::BeginEvent(load_log, LoadLog::TYPE_SOCKS5_CONNECT);
61 62
62 LoadLog::BeginEvent(load_log, LoadLog::TYPE_SOCKS5_CONNECT); 63 // If a host resolver was given, try to resolve the address locally.
64 // Otherwise let the proxy server handle the resolving.
65 if (host_resolver_.get()) {
66 next_state_ = STATE_RESOLVE_HOST;
67 } else {
68 next_state_ = STATE_GREET_WRITE;
69 address_type_ = kEndPointFailedDomain;
70 }
63 71
64 int rv = DoLoop(OK); 72 int rv = DoLoop(OK);
65 if (rv == ERR_IO_PENDING) { 73 if (rv == ERR_IO_PENDING) {
66 user_callback_ = callback; 74 user_callback_ = callback;
67 } else { 75 } else {
68 LoadLog::EndEvent(load_log, LoadLog::TYPE_SOCKS5_CONNECT); 76 LoadLog::EndEvent(load_log, LoadLog::TYPE_SOCKS5_CONNECT);
69 load_log_ = NULL; 77 load_log_ = NULL;
70 } 78 }
71 return rv; 79 return rv;
72 } 80 }
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 break; 192 break;
185 } 193 }
186 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); 194 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE);
187 return rv; 195 return rv;
188 } 196 }
189 197
190 int SOCKS5ClientSocket::DoResolveHost() { 198 int SOCKS5ClientSocket::DoResolveHost() {
191 DCHECK_EQ(kEndPointUnresolved, address_type_); 199 DCHECK_EQ(kEndPointUnresolved, address_type_);
192 200
193 next_state_ = STATE_RESOLVE_HOST_COMPLETE; 201 next_state_ = STATE_RESOLVE_HOST_COMPLETE;
194 return host_resolver_.Resolve( 202 return host_resolver_->Resolve(
195 host_request_info_, &addresses_, &io_callback_, load_log_); 203 host_request_info_, &addresses_, &io_callback_, load_log_);
196 } 204 }
197 205
198 int SOCKS5ClientSocket::DoResolveHostComplete(int result) { 206 int SOCKS5ClientSocket::DoResolveHostComplete(int result) {
199 DCHECK_EQ(kEndPointUnresolved, address_type_); 207 DCHECK_EQ(kEndPointUnresolved, address_type_);
200 208
201 bool ok = (result == OK); 209 bool ok = (result == OK);
202 next_state_ = STATE_GREET_WRITE; 210 next_state_ = STATE_GREET_WRITE;
203 if (ok) { 211 if (ok) {
204 DCHECK(addresses_.head()); 212 DCHECK(addresses_.head());
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 } 444 }
437 445
438 #if defined(OS_LINUX) 446 #if defined(OS_LINUX)
439 int SOCKS5ClientSocket::GetPeerName(struct sockaddr* name, 447 int SOCKS5ClientSocket::GetPeerName(struct sockaddr* name,
440 socklen_t* namelen) { 448 socklen_t* namelen) {
441 return transport_->GetPeerName(name, namelen); 449 return transport_->GetPeerName(name, namelen);
442 } 450 }
443 #endif 451 #endif
444 452
445 } // namespace net 453 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698