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 | |
211 LOG(1) << "StartTls socket connect status is " << status; | |
209 if (status != net::ERR_IO_PENDING) { | 212 if (status != net::ERR_IO_PENDING) { |
210 ProcessTlsSslConnectDone(status); | 213 ProcessTlsSslConnectDone(status); |
211 } | 214 } |
212 } | 215 } |
213 | 216 |
214 void P2PSocketHostTcpBase::ProcessTlsSslConnectDone(int status) { | 217 void P2PSocketHostTcpBase::ProcessTlsSslConnectDone(int status) { |
215 DCHECK_NE(status, net::ERR_IO_PENDING); | 218 DCHECK_NE(status, net::ERR_IO_PENDING); |
216 DCHECK_EQ(state_, STATE_TLS_CONNECTING); | 219 DCHECK_EQ(state_, STATE_TLS_CONNECTING); |
217 if (status != net::OK) { | 220 if (status != net::OK) { |
221 LOG(WARNING) << "Error from connecting TLS socket, status=" << status; | |
218 OnError(); | 222 OnError(); |
219 return; | 223 return; |
220 } | 224 } |
221 OnOpen(); | 225 OnOpen(); |
222 } | 226 } |
223 | 227 |
224 void P2PSocketHostTcpBase::OnOpen() { | 228 void P2PSocketHostTcpBase::OnOpen() { |
225 state_ = STATE_OPEN; | 229 state_ = STATE_OPEN; |
226 // Setting socket send and receive buffer size. | 230 // Setting socket send and receive buffer size. |
227 if (net::OK != socket_->SetReceiveBufferSize(kRecvSocketBufferSize)) { | 231 if (net::OK != socket_->SetReceiveBufferSize(kRecvSocketBufferSize)) { |
(...skipping 23 matching lines...) Expand all Loading... | |
251 << " address: " << result; | 255 << " address: " << result; |
252 OnError(); | 256 OnError(); |
253 return false; | 257 return false; |
254 } | 258 } |
255 | 259 |
256 VLOG(1) << "Local address: " << local_address.ToString(); | 260 VLOG(1) << "Local address: " << local_address.ToString(); |
257 | 261 |
258 net::IPEndPoint remote_address; | 262 net::IPEndPoint remote_address; |
259 | 263 |
260 // |remote_address| could be empty if it is connected through a proxy. | 264 // |remote_address| could be empty if it is connected through a proxy. |
261 result = socket_->GetPeerAddress(&remote_address); | 265 result = socket_->GetPeerAddress(&remote_address); |
Ryan Sleevi
2015/03/05 18:07:34
How is this possible? I assume you can reproduce t
| |
262 if (result < 0) { | 266 if (result < 0) { |
263 LOG(ERROR) << "P2PSocketHostTcpBase::OnConnected: unable to get peer" | 267 LOG(ERROR) << "P2PSocketHostTcpBase::OnConnected: unable to get peer" |
264 << " address: " << result; | 268 << " address: " << result; |
265 OnError(); | 269 OnError(); |
266 return false; | 270 return false; |
267 } | 271 } |
268 VLOG(1) << "Remote address: " << remote_address.ToString(); | 272 |
269 if (remote_address_.ip_address.address().empty() && | 273 if (!remote_address.address().empty()) { |
270 !remote_address.address().empty()) { | 274 VLOG(1) << "Remote address: " << remote_address.ToString(); |
271 // Save |remote_address| if address is empty. | 275 if (remote_address_.ip_address.address().empty()) { |
272 remote_address_.ip_address = remote_address; | 276 // Save |remote_address| if address is empty. |
277 remote_address_.ip_address = remote_address; | |
278 } | |
273 } | 279 } |
274 | 280 |
275 // If we are not doing TLS, we are ready to send data now. | 281 // 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 | 282 // 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 | 283 // successful. So no buffering will be done at socket handlers if any |
278 // packets sent before that by the application. | 284 // packets sent before that by the application. |
279 message_sender_->Send(new P2PMsg_OnSocketCreated( | 285 message_sender_->Send(new P2PMsg_OnSocketCreated( |
280 id_, local_address, remote_address)); | 286 id_, local_address, remote_address)); |
281 return true; | 287 return true; |
282 } | 288 } |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
618 } else { | 624 } else { |
619 packet_size += kTurnChannelDataHeaderSize; | 625 packet_size += kTurnChannelDataHeaderSize; |
620 // Calculate any padding if present. | 626 // Calculate any padding if present. |
621 if (packet_size % 4) | 627 if (packet_size % 4) |
622 *pad_bytes = 4 - packet_size % 4; | 628 *pad_bytes = 4 - packet_size % 4; |
623 } | 629 } |
624 return packet_size; | 630 return packet_size; |
625 } | 631 } |
626 | 632 |
627 } // namespace content | 633 } // namespace content |
OLD | NEW |