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 22 matching lines...) Expand all Loading... | |
250 LOG(ERROR) << "P2PSocketHostTcpBase::OnConnected: unable to get local" | 253 LOG(ERROR) << "P2PSocketHostTcpBase::OnConnected: unable to get local" |
251 << " address: " << result; | 254 << " address: " << result; |
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 // GetPeerAddress returns ERR_NAME_NOT_RESOLVED if the socket is connected |
264 // through a proxy. | |
261 result = socket_->GetPeerAddress(&remote_address); | 265 result = socket_->GetPeerAddress(&remote_address); |
262 if (result < 0) { | 266 if (result < 0 && result != net::ERR_NAME_NOT_RESOLVED) { |
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 } | |
279 } else { | |
280 VLOG(1) << "Cannot get remote address due to proxy."; | |
Sergey Ulanov
2015/03/11 18:35:22
Suggest rewording: "Remote address is unknown, con
| |
273 } | 281 } |
274 | 282 |
275 // If we are not doing TLS, we are ready to send data now. | 283 // 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 | 284 // 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 | 285 // successful. So no buffering will be done at socket handlers if any |
278 // packets sent before that by the application. | 286 // packets sent before that by the application. |
279 message_sender_->Send(new P2PMsg_OnSocketCreated( | 287 message_sender_->Send(new P2PMsg_OnSocketCreated( |
280 id_, local_address, remote_address)); | 288 id_, local_address, remote_address)); |
281 return true; | 289 return true; |
282 } | 290 } |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
618 } else { | 626 } else { |
619 packet_size += kTurnChannelDataHeaderSize; | 627 packet_size += kTurnChannelDataHeaderSize; |
620 // Calculate any padding if present. | 628 // Calculate any padding if present. |
621 if (packet_size % 4) | 629 if (packet_size % 4) |
622 *pad_bytes = 4 - packet_size % 4; | 630 *pad_bytes = 4 - packet_size % 4; |
623 } | 631 } |
624 return packet_size; | 632 return packet_size; |
625 } | 633 } |
626 | 634 |
627 } // namespace content | 635 } // namespace content |
OLD | NEW |