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

Side by Side Diff: content/browser/renderer_host/p2p/socket_host_tcp.cc

Issue 365903007: Handle unresolved remote hostname for TCP sockets. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/renderer_host/p2p/socket_host_tcp.h" 5 #include "content/browser/renderer_host/p2p/socket_host_tcp.h"
6 6
7 #include "base/sys_byteorder.h" 7 #include "base/sys_byteorder.h"
8 #include "content/common/p2p_messages.h" 8 #include "content/common/p2p_messages.h"
9 #include "ipc/ipc_sender.h" 9 #include "ipc/ipc_sender.h"
10 #include "jingle/glue/fake_ssl_client_socket.h" 10 #include "jingle/glue/fake_ssl_client_socket.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 bool P2PSocketHostTcpBase::Init(const net::IPEndPoint& local_address, 79 bool P2PSocketHostTcpBase::Init(const net::IPEndPoint& local_address,
80 const P2PHostAndIPEndPoint& remote_address) { 80 const P2PHostAndIPEndPoint& remote_address) {
81 DCHECK_EQ(state_, STATE_UNINITIALIZED); 81 DCHECK_EQ(state_, STATE_UNINITIALIZED);
82 82
83 remote_address_ = remote_address; 83 remote_address_ = remote_address;
84 state_ = STATE_CONNECTING; 84 state_ = STATE_CONNECTING;
85 85
86 net::HostPortPair dest_host_port_pair = 86 net::HostPortPair dest_host_port_pair =
87 net::HostPortPair::FromIPEndPoint(remote_address.ip_address); 87 net::HostPortPair::FromIPEndPoint(remote_address.ip_address);
88 // If there is no resolved address, let's try with domain name, assuming
89 // socket layer will do the DNS resolve.
90 if (remote_address.ip_address.address().empty()) {
91 dest_host_port_pair = net::HostPortPair(
92 remote_address.hostname, remote_address.ip_address.port());
Sergey Ulanov 2014/07/03 03:31:06 DCHECK that hostname is not empty?
Mallinath (Gone from Chromium) 2014/07/07 17:56:44 Done.
93 }
94
88 // TODO(mallinath) - We are ignoring local_address altogether. We should 95 // TODO(mallinath) - We are ignoring local_address altogether. We should
89 // find a way to inject this into ProxyResolvingClientSocket. This could be 96 // find a way to inject this into ProxyResolvingClientSocket. This could be
90 // a problem on multi-homed host. 97 // a problem on multi-homed host.
91 98
92 // The default SSLConfig is good enough for us for now. 99 // The default SSLConfig is good enough for us for now.
93 const net::SSLConfig ssl_config; 100 const net::SSLConfig ssl_config;
94 socket_.reset(new jingle_glue::ProxyResolvingClientSocket( 101 socket_.reset(new jingle_glue::ProxyResolvingClientSocket(
95 NULL, // Default socket pool provided by the net::Proxy. 102 NULL, // Default socket pool provided by the net::Proxy.
96 url_context_, 103 url_context_,
97 ssl_config, 104 ssl_config,
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 << kSendSocketBufferSize; 224 << kSendSocketBufferSize;
218 } 225 }
219 226
220 DoSendSocketCreateMsg(); 227 DoSendSocketCreateMsg();
221 DoRead(); 228 DoRead();
222 } 229 }
223 230
224 void P2PSocketHostTcpBase::DoSendSocketCreateMsg() { 231 void P2PSocketHostTcpBase::DoSendSocketCreateMsg() {
225 DCHECK(socket_.get()); 232 DCHECK(socket_.get());
226 233
227 net::IPEndPoint address; 234 net::IPEndPoint local_address;
228 int result = socket_->GetLocalAddress(&address); 235 int result = socket_->GetLocalAddress(&local_address);
229 if (result < 0) { 236 if (result < 0) {
230 LOG(ERROR) << "P2PSocketHostTcpBase::OnConnected: unable to get local" 237 LOG(ERROR) << "P2PSocketHostTcpBase::OnConnected: unable to get local"
231 << " address: " << result; 238 << " address: " << result;
232 OnError(); 239 OnError();
233 return; 240 return;
234 } 241 }
235 242
236 VLOG(1) << "Local address: " << address.ToString(); 243 VLOG(1) << "Local address: " << local_address.ToString();
244
245 net::IPEndPoint remote_address;
246 result = socket_->GetPeerAddress(&remote_address);
247 if (result < 0) {
248 LOG(ERROR) << "P2PSocketHostTcpBase::OnConnected: unable to get peer"
249 << " address: " << result;
250 OnError();
251 return;
252 }
253 VLOG(1) << "Remote address: " << remote_address.ToString();
254 if (remote_address_.ip_address.address().empty()) {
255 // Save |remote_address| if address is empty.
256 remote_address_.ip_address = remote_address;
257 }
237 258
238 // If we are not doing TLS, we are ready to send data now. 259 // If we are not doing TLS, we are ready to send data now.
239 // In case of TLS SignalConnect will be sent only after TLS handshake is 260 // In case of TLS SignalConnect will be sent only after TLS handshake is
240 // successfull. So no buffering will be done at socket handlers if any 261 // successfull. So no buffering will be done at socket handlers if any
241 // packets sent before that by the application. 262 // packets sent before that by the application.
242 message_sender_->Send(new P2PMsg_OnSocketCreated(id_, address)); 263 message_sender_->Send(new P2PMsg_OnSocketCreated(
264 id_, local_address, remote_address));
243 } 265 }
244 266
245 void P2PSocketHostTcpBase::DoRead() { 267 void P2PSocketHostTcpBase::DoRead() {
246 int result; 268 int result;
247 do { 269 do {
248 if (!read_buffer_.get()) { 270 if (!read_buffer_.get()) {
249 read_buffer_ = new net::GrowableIOBuffer(); 271 read_buffer_ = new net::GrowableIOBuffer();
250 read_buffer_->SetCapacity(kReadBufferSize); 272 read_buffer_->SetCapacity(kReadBufferSize);
251 } else if (read_buffer_->RemainingCapacity() < kReadBufferSize) { 273 } else if (read_buffer_->RemainingCapacity() < kReadBufferSize) {
252 // Make sure that we always have at least kReadBufferSize of 274 // Make sure that we always have at least kReadBufferSize of
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 } else { 591 } else {
570 packet_size += kTurnChannelDataHeaderSize; 592 packet_size += kTurnChannelDataHeaderSize;
571 // Calculate any padding if present. 593 // Calculate any padding if present.
572 if (packet_size % 4) 594 if (packet_size % 4)
573 *pad_bytes = 4 - packet_size % 4; 595 *pad_bytes = 4 - packet_size % 4;
574 } 596 }
575 return packet_size; 597 return packet_size;
576 } 598 }
577 599
578 } // namespace content 600 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/p2p/socket_host_tcp_server.cc » ('j') | content/common/p2p_messages.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698