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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 DCHECK(socket_.get()); | 58 DCHECK(socket_.get()); |
59 socket_.reset(); | 59 socket_.reset(); |
60 } | 60 } |
61 } | 61 } |
62 | 62 |
63 bool P2PSocketHostTcpBase::InitAccepted(const net::IPEndPoint& remote_address, | 63 bool P2PSocketHostTcpBase::InitAccepted(const net::IPEndPoint& remote_address, |
64 net::StreamSocket* socket) { | 64 net::StreamSocket* socket) { |
65 DCHECK(socket); | 65 DCHECK(socket); |
66 DCHECK_EQ(state_, STATE_UNINITIALIZED); | 66 DCHECK_EQ(state_, STATE_UNINITIALIZED); |
67 | 67 |
68 remote_address_ = remote_address; | 68 remote_address_.ip_address = remote_address; |
69 // TODO(ronghuawu): Add FakeSSLServerSocket. | 69 // TODO(ronghuawu): Add FakeSSLServerSocket. |
70 socket_.reset(socket); | 70 socket_.reset(socket); |
71 state_ = STATE_OPEN; | 71 state_ = STATE_OPEN; |
72 DoRead(); | 72 DoRead(); |
73 return state_ != STATE_ERROR; | 73 return state_ != STATE_ERROR; |
74 } | 74 } |
75 | 75 |
76 bool P2PSocketHostTcpBase::Init(const net::IPEndPoint& local_address, | 76 bool P2PSocketHostTcpBase::Init(const net::IPEndPoint& local_address, |
77 const net::IPEndPoint& remote_address) { | 77 const P2PHostAndIPEndPoint& remote_address) { |
78 DCHECK_EQ(state_, STATE_UNINITIALIZED); | 78 DCHECK_EQ(state_, STATE_UNINITIALIZED); |
79 | 79 |
80 remote_address_ = remote_address; | 80 remote_address_ = remote_address; |
81 state_ = STATE_CONNECTING; | 81 state_ = STATE_CONNECTING; |
82 | 82 |
83 net::HostPortPair dest_host_port_pair = | 83 net::HostPortPair dest_host_port_pair = |
84 net::HostPortPair::FromIPEndPoint(remote_address); | 84 net::HostPortPair::FromIPEndPoint(remote_address.ip_address); |
85 // TODO(mallinath) - We are ignoring local_address altogether. We should | 85 // TODO(mallinath) - We are ignoring local_address altogether. We should |
86 // find a way to inject this into ProxyResolvingClientSocket. This could be | 86 // find a way to inject this into ProxyResolvingClientSocket. This could be |
87 // a problem on multi-homed host. | 87 // a problem on multi-homed host. |
88 | 88 |
89 // The default SSLConfig is good enough for us for now. | 89 // The default SSLConfig is good enough for us for now. |
90 const net::SSLConfig ssl_config; | 90 const net::SSLConfig ssl_config; |
91 socket_.reset(new jingle_glue::ProxyResolvingClientSocket( | 91 socket_.reset(new jingle_glue::ProxyResolvingClientSocket( |
92 NULL, // Default socket pool provided by the net::Proxy. | 92 NULL, // Default socket pool provided by the net::Proxy. |
93 url_context_, | 93 url_context_, |
94 ssl_config, | 94 ssl_config, |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 166 |
167 net::SSLClientSocketContext context; | 167 net::SSLClientSocketContext context; |
168 context.cert_verifier = url_context_->GetURLRequestContext()->cert_verifier(); | 168 context.cert_verifier = url_context_->GetURLRequestContext()->cert_verifier(); |
169 context.transport_security_state = | 169 context.transport_security_state = |
170 url_context_->GetURLRequestContext()->transport_security_state(); | 170 url_context_->GetURLRequestContext()->transport_security_state(); |
171 DCHECK(context.transport_security_state); | 171 DCHECK(context.transport_security_state); |
172 | 172 |
173 // Default ssl config. | 173 // Default ssl config. |
174 const net::SSLConfig ssl_config; | 174 const net::SSLConfig ssl_config; |
175 net::HostPortPair dest_host_port_pair = | 175 net::HostPortPair dest_host_port_pair = |
176 net::HostPortPair::FromIPEndPoint(remote_address_); | 176 net::HostPortPair::FromIPEndPoint(remote_address_.ip_address); |
| 177 if (!remote_address_.hostname.empty()) |
| 178 dest_host_port_pair.set_host(remote_address_.hostname); |
| 179 |
177 net::ClientSocketFactory* socket_factory = | 180 net::ClientSocketFactory* socket_factory = |
178 net::ClientSocketFactory::GetDefaultFactory(); | 181 net::ClientSocketFactory::GetDefaultFactory(); |
179 DCHECK(socket_factory); | 182 DCHECK(socket_factory); |
180 | 183 |
181 socket_ = socket_factory->CreateSSLClientSocket( | 184 socket_ = socket_factory->CreateSSLClientSocket( |
182 socket_handle.Pass(), dest_host_port_pair, ssl_config, context); | 185 socket_handle.Pass(), dest_host_port_pair, ssl_config, context); |
183 int status = socket_->Connect( | 186 int status = socket_->Connect( |
184 base::Bind(&P2PSocketHostTcpBase::ProcessTlsSslConnectDone, | 187 base::Bind(&P2PSocketHostTcpBase::ProcessTlsSslConnectDone, |
185 base::Unretained(this))); | 188 base::Unretained(this))); |
186 if (status != net::ERR_IO_PENDING) { | 189 if (status != net::ERR_IO_PENDING) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 } | 269 } |
267 | 270 |
268 void P2PSocketHostTcpBase::OnPacket(const std::vector<char>& data) { | 271 void P2PSocketHostTcpBase::OnPacket(const std::vector<char>& data) { |
269 if (!connected_) { | 272 if (!connected_) { |
270 P2PSocketHost::StunMessageType type; | 273 P2PSocketHost::StunMessageType type; |
271 bool stun = GetStunPacketType(&*data.begin(), data.size(), &type); | 274 bool stun = GetStunPacketType(&*data.begin(), data.size(), &type); |
272 if (stun && IsRequestOrResponse(type)) { | 275 if (stun && IsRequestOrResponse(type)) { |
273 connected_ = true; | 276 connected_ = true; |
274 } else if (!stun || type == STUN_DATA_INDICATION) { | 277 } else if (!stun || type == STUN_DATA_INDICATION) { |
275 LOG(ERROR) << "Received unexpected data packet from " | 278 LOG(ERROR) << "Received unexpected data packet from " |
276 << remote_address_.ToString() | 279 << remote_address_.ip_address.ToString() |
277 << " before STUN binding is finished. " | 280 << " before STUN binding is finished. " |
278 << "Terminating connection."; | 281 << "Terminating connection."; |
279 OnError(); | 282 OnError(); |
280 return; | 283 return; |
281 } | 284 } |
282 } | 285 } |
283 | 286 |
284 message_sender_->Send(new P2PMsg_OnDataReceived( | 287 message_sender_->Send(new P2PMsg_OnDataReceived( |
285 id_, remote_address_, data, base::TimeTicks::Now())); | 288 id_, remote_address_.ip_address, data, base::TimeTicks::Now())); |
286 } | 289 } |
287 | 290 |
288 // Note: dscp is not actually used on TCP sockets as this point, | 291 // Note: dscp is not actually used on TCP sockets as this point, |
289 // but may be honored in the future. | 292 // but may be honored in the future. |
290 void P2PSocketHostTcpBase::Send(const net::IPEndPoint& to, | 293 void P2PSocketHostTcpBase::Send(const net::IPEndPoint& to, |
291 const std::vector<char>& data, | 294 const std::vector<char>& data, |
292 const talk_base::PacketOptions& options, | 295 const talk_base::PacketOptions& options, |
293 uint64 packet_id) { | 296 uint64 packet_id) { |
294 if (!socket_) { | 297 if (!socket_) { |
295 // The Send message may be sent after the an OnError message was | 298 // The Send message may be sent after the an OnError message was |
296 // sent by hasn't been processed the renderer. | 299 // sent by hasn't been processed the renderer. |
297 return; | 300 return; |
298 } | 301 } |
299 | 302 |
300 if (!(to == remote_address_)) { | 303 if (!(to == remote_address_.ip_address)) { |
301 // Renderer should use this socket only to send data to |remote_address_|. | 304 // Renderer should use this socket only to send data to |remote_address_|. |
302 NOTREACHED(); | 305 NOTREACHED(); |
303 OnError(); | 306 OnError(); |
304 return; | 307 return; |
305 } | 308 } |
306 | 309 |
307 if (!connected_) { | 310 if (!connected_) { |
308 P2PSocketHost::StunMessageType type = P2PSocketHost::StunMessageType(); | 311 P2PSocketHost::StunMessageType type = P2PSocketHost::StunMessageType(); |
309 bool stun = GetStunPacketType(&*data.begin(), data.size(), &type); | 312 bool stun = GetStunPacketType(&*data.begin(), data.size(), &type); |
310 if (!stun || type == STUN_DATA_INDICATION) { | 313 if (!stun || type == STUN_DATA_INDICATION) { |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 } else { | 547 } else { |
545 packet_size += kTurnChannelDataHeaderSize; | 548 packet_size += kTurnChannelDataHeaderSize; |
546 // Calculate any padding if present. | 549 // Calculate any padding if present. |
547 if (packet_size % 4) | 550 if (packet_size % 4) |
548 *pad_bytes = 4 - packet_size % 4; | 551 *pad_bytes = 4 - packet_size % 4; |
549 } | 552 } |
550 return packet_size; | 553 return packet_size; |
551 } | 554 } |
552 | 555 |
553 } // namespace content | 556 } // namespace content |
OLD | NEW |