| OLD | NEW |
| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 } | 135 } |
| 136 | 136 |
| 137 state_ = STATE_ERROR; | 137 state_ = STATE_ERROR; |
| 138 } | 138 } |
| 139 | 139 |
| 140 void P2PSocketHostTcpBase::OnConnected(int result) { | 140 void P2PSocketHostTcpBase::OnConnected(int result) { |
| 141 DCHECK_EQ(state_, STATE_CONNECTING); | 141 DCHECK_EQ(state_, STATE_CONNECTING); |
| 142 DCHECK_NE(result, net::ERR_IO_PENDING); | 142 DCHECK_NE(result, net::ERR_IO_PENDING); |
| 143 | 143 |
| 144 if (result != net::OK) { | 144 if (result != net::OK) { |
| 145 LOG(WARNING) << "Error from connecting socket, result=" << result; |
| 145 OnError(); | 146 OnError(); |
| 146 return; | 147 return; |
| 147 } | 148 } |
| 148 | 149 |
| 149 if (IsTlsClientSocket(type_)) { | 150 if (IsTlsClientSocket(type_)) { |
| 150 state_ = STATE_TLS_CONNECTING; | 151 state_ = STATE_TLS_CONNECTING; |
| 151 StartTls(); | 152 StartTls(); |
| 152 } else if (IsPseudoTlsClientSocket(type_)) { | 153 } else if (IsPseudoTlsClientSocket(type_)) { |
| 153 scoped_ptr<net::StreamSocket> transport_socket = socket_.Pass(); | 154 scoped_ptr<net::StreamSocket> transport_socket = socket_.Pass(); |
| 154 socket_.reset( | 155 socket_.reset( |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 | 200 |
| 200 net::ClientSocketFactory* socket_factory = | 201 net::ClientSocketFactory* socket_factory = |
| 201 net::ClientSocketFactory::GetDefaultFactory(); | 202 net::ClientSocketFactory::GetDefaultFactory(); |
| 202 DCHECK(socket_factory); | 203 DCHECK(socket_factory); |
| 203 | 204 |
| 204 socket_ = socket_factory->CreateSSLClientSocket( | 205 socket_ = socket_factory->CreateSSLClientSocket( |
| 205 socket_handle.Pass(), dest_host_port_pair, ssl_config, context); | 206 socket_handle.Pass(), dest_host_port_pair, ssl_config, context); |
| 206 int status = socket_->Connect( | 207 int status = socket_->Connect( |
| 207 base::Bind(&P2PSocketHostTcpBase::ProcessTlsSslConnectDone, | 208 base::Bind(&P2PSocketHostTcpBase::ProcessTlsSslConnectDone, |
| 208 base::Unretained(this))); | 209 base::Unretained(this))); |
| 210 |
| 209 if (status != net::ERR_IO_PENDING) { | 211 if (status != net::ERR_IO_PENDING) { |
| 210 ProcessTlsSslConnectDone(status); | 212 ProcessTlsSslConnectDone(status); |
| 211 } | 213 } |
| 212 } | 214 } |
| 213 | 215 |
| 214 void P2PSocketHostTcpBase::ProcessTlsSslConnectDone(int status) { | 216 void P2PSocketHostTcpBase::ProcessTlsSslConnectDone(int status) { |
| 215 DCHECK_NE(status, net::ERR_IO_PENDING); | 217 DCHECK_NE(status, net::ERR_IO_PENDING); |
| 216 DCHECK_EQ(state_, STATE_TLS_CONNECTING); | 218 DCHECK_EQ(state_, STATE_TLS_CONNECTING); |
| 217 if (status != net::OK) { | 219 if (status != net::OK) { |
| 220 LOG(WARNING) << "Error from connecting TLS socket, status=" << status; |
| 218 OnError(); | 221 OnError(); |
| 219 return; | 222 return; |
| 220 } | 223 } |
| 221 OnOpen(); | 224 OnOpen(); |
| 222 } | 225 } |
| 223 | 226 |
| 224 void P2PSocketHostTcpBase::OnOpen() { | 227 void P2PSocketHostTcpBase::OnOpen() { |
| 225 state_ = STATE_OPEN; | 228 state_ = STATE_OPEN; |
| 226 // Setting socket send and receive buffer size. | 229 // Setting socket send and receive buffer size. |
| 227 if (net::OK != socket_->SetReceiveBufferSize(kRecvSocketBufferSize)) { | 230 if (net::OK != socket_->SetReceiveBufferSize(kRecvSocketBufferSize)) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 252 OnError(); | 255 OnError(); |
| 253 return false; | 256 return false; |
| 254 } | 257 } |
| 255 | 258 |
| 256 VLOG(1) << "Local address: " << local_address.ToString(); | 259 VLOG(1) << "Local address: " << local_address.ToString(); |
| 257 | 260 |
| 258 net::IPEndPoint remote_address; | 261 net::IPEndPoint remote_address; |
| 259 | 262 |
| 260 // |remote_address| could be empty if it is connected through a proxy. | 263 // |remote_address| could be empty if it is connected through a proxy. |
| 261 result = socket_->GetPeerAddress(&remote_address); | 264 result = socket_->GetPeerAddress(&remote_address); |
| 262 if (result < 0) { | 265 if (result < 0 && result != net::ERR_NAME_NOT_RESOLVED) { |
| 263 LOG(ERROR) << "P2PSocketHostTcpBase::OnConnected: unable to get peer" | 266 LOG(ERROR) << "P2PSocketHostTcpBase::OnConnected: unable to get peer" |
| 264 << " address: " << result; | 267 << " address: " << result; |
| 265 OnError(); | 268 OnError(); |
| 266 return false; | 269 return false; |
| 267 } | 270 } |
| 268 VLOG(1) << "Remote address: " << remote_address.ToString(); | 271 |
| 269 if (remote_address_.ip_address.address().empty() && | 272 if (!remote_address.address().empty()) { |
| 270 !remote_address.address().empty()) { | 273 VLOG(1) << "Remote address: " << remote_address.ToString(); |
| 271 // Save |remote_address| if address is empty. | 274 if (remote_address_.ip_address.address().empty()) { |
| 272 remote_address_.ip_address = remote_address; | 275 // Save |remote_address| if address is empty. |
| 276 remote_address_.ip_address = remote_address; |
| 277 } |
| 273 } | 278 } |
| 274 | 279 |
| 275 // If we are not doing TLS, we are ready to send data now. | 280 // If we are not doing TLS, we are ready to send data now. |
| 276 // In case of TLS SignalConnect will be sent only after TLS handshake is | 281 // In case of TLS SignalConnect will be sent only after TLS handshake is |
| 277 // successful. So no buffering will be done at socket handlers if any | 282 // successful. So no buffering will be done at socket handlers if any |
| 278 // packets sent before that by the application. | 283 // packets sent before that by the application. |
| 279 message_sender_->Send(new P2PMsg_OnSocketCreated( | 284 message_sender_->Send(new P2PMsg_OnSocketCreated( |
| 280 id_, local_address, remote_address)); | 285 id_, local_address, remote_address)); |
| 281 return true; | 286 return true; |
| 282 } | 287 } |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 } else { | 623 } else { |
| 619 packet_size += kTurnChannelDataHeaderSize; | 624 packet_size += kTurnChannelDataHeaderSize; |
| 620 // Calculate any padding if present. | 625 // Calculate any padding if present. |
| 621 if (packet_size % 4) | 626 if (packet_size % 4) |
| 622 *pad_bytes = 4 - packet_size % 4; | 627 *pad_bytes = 4 - packet_size % 4; |
| 623 } | 628 } |
| 624 return packet_size; | 629 return packet_size; |
| 625 } | 630 } |
| 626 | 631 |
| 627 } // namespace content | 632 } // namespace content |
| OLD | NEW |