| 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/renderer/p2p/ipc_socket_factory.h" | 5 #include "content/renderer/p2p/ipc_socket_factory.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 const talk_base::SocketAddress& addr, | 86 const talk_base::SocketAddress& addr, |
| 87 const talk_base::PacketOptions& options) OVERRIDE; | 87 const talk_base::PacketOptions& options) OVERRIDE; |
| 88 virtual int Close() OVERRIDE; | 88 virtual int Close() OVERRIDE; |
| 89 virtual State GetState() const OVERRIDE; | 89 virtual State GetState() const OVERRIDE; |
| 90 virtual int GetOption(talk_base::Socket::Option option, int* value) OVERRIDE; | 90 virtual int GetOption(talk_base::Socket::Option option, int* value) OVERRIDE; |
| 91 virtual int SetOption(talk_base::Socket::Option option, int value) OVERRIDE; | 91 virtual int SetOption(talk_base::Socket::Option option, int value) OVERRIDE; |
| 92 virtual int GetError() const OVERRIDE; | 92 virtual int GetError() const OVERRIDE; |
| 93 virtual void SetError(int error) OVERRIDE; | 93 virtual void SetError(int error) OVERRIDE; |
| 94 | 94 |
| 95 // P2PSocketClientDelegate implementation. | 95 // P2PSocketClientDelegate implementation. |
| 96 virtual void OnOpen(const net::IPEndPoint& address) OVERRIDE; | 96 virtual void OnOpen(const net::IPEndPoint& address, |
| 97 const net::IPEndPoint& remote_address) OVERRIDE; |
| 97 virtual void OnIncomingTcpConnection( | 98 virtual void OnIncomingTcpConnection( |
| 98 const net::IPEndPoint& address, | 99 const net::IPEndPoint& address, |
| 99 P2PSocketClient* client) OVERRIDE; | 100 P2PSocketClient* client) OVERRIDE; |
| 100 virtual void OnSendComplete() OVERRIDE; | 101 virtual void OnSendComplete() OVERRIDE; |
| 101 virtual void OnError() OVERRIDE; | 102 virtual void OnError() OVERRIDE; |
| 102 virtual void OnDataReceived(const net::IPEndPoint& address, | 103 virtual void OnDataReceived(const net::IPEndPoint& address, |
| 103 const std::vector<char>& data, | 104 const std::vector<char>& data, |
| 104 const base::TimeTicks& timestamp) OVERRIDE; | 105 const base::TimeTicks& timestamp) OVERRIDE; |
| 105 | 106 |
| 106 private: | 107 private: |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 local_address_ = local_address; | 227 local_address_ = local_address; |
| 227 remote_address_ = remote_address; | 228 remote_address_ = remote_address; |
| 228 state_ = IS_OPENING; | 229 state_ = IS_OPENING; |
| 229 | 230 |
| 230 net::IPEndPoint local_endpoint; | 231 net::IPEndPoint local_endpoint; |
| 231 if (!jingle_glue::SocketAddressToIPEndPoint( | 232 if (!jingle_glue::SocketAddressToIPEndPoint( |
| 232 local_address, &local_endpoint)) { | 233 local_address, &local_endpoint)) { |
| 233 return false; | 234 return false; |
| 234 } | 235 } |
| 235 | 236 |
| 237 if (remote_address.IsNil()) { |
| 238 return false; |
| 239 } |
| 240 |
| 236 net::IPEndPoint remote_endpoint; | 241 net::IPEndPoint remote_endpoint; |
| 237 if (!remote_address.IsNil() && | 242 if (!jingle_glue::SocketAddressToIPEndPoint( |
| 238 !jingle_glue::SocketAddressToIPEndPoint( | 243 remote_address, &remote_endpoint) && !IsTcpClientSocket(type_)) { |
| 239 remote_address, &remote_endpoint)) { | 244 // Non TCP sockets must have a resolved remote address. |
| 240 return false; | 245 return false; |
| 241 } | 246 } |
| 242 | 247 |
| 243 // We need to send both resolved and unresolved address in Init. Unresolved | 248 // We need to send both resolved and unresolved address in Init. Unresolved |
| 244 // address will be used in case of TLS for certificate hostname matching. | 249 // address will be used in case of TLS for certificate hostname matching. |
| 245 // Certificate will be tied to domain name not to IP address. | 250 // Certificate will be tied to domain name not to IP address. |
| 246 P2PHostAndIPEndPoint remote_info(remote_address.hostname(), remote_endpoint); | 251 P2PHostAndIPEndPoint remote_info(remote_address.hostname(), remote_endpoint); |
| 247 | 252 |
| 248 client->Init(type, local_endpoint, remote_info, this); | 253 client->Init(type, local_endpoint, remote_info, this); |
| 249 | 254 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 int IpcPacketSocket::GetError() const { | 424 int IpcPacketSocket::GetError() const { |
| 420 DCHECK_EQ(base::MessageLoop::current(), message_loop_); | 425 DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
| 421 return error_; | 426 return error_; |
| 422 } | 427 } |
| 423 | 428 |
| 424 void IpcPacketSocket::SetError(int error) { | 429 void IpcPacketSocket::SetError(int error) { |
| 425 DCHECK_EQ(base::MessageLoop::current(), message_loop_); | 430 DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
| 426 error_ = error; | 431 error_ = error; |
| 427 } | 432 } |
| 428 | 433 |
| 429 void IpcPacketSocket::OnOpen(const net::IPEndPoint& address) { | 434 void IpcPacketSocket::OnOpen(const net::IPEndPoint& address, |
| 435 const net::IPEndPoint& remote_address) { |
| 430 DCHECK_EQ(base::MessageLoop::current(), message_loop_); | 436 DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
| 431 | 437 |
| 432 if (!jingle_glue::IPEndPointToSocketAddress(address, &local_address_)) { | 438 if (!jingle_glue::IPEndPointToSocketAddress(address, &local_address_)) { |
| 433 // Always expect correct IPv4 address to be allocated. | 439 // Always expect correct IPv4 address to be allocated. |
| 434 NOTREACHED(); | 440 NOTREACHED(); |
| 435 OnError(); | 441 OnError(); |
| 436 return; | 442 return; |
| 437 } | 443 } |
| 438 | 444 |
| 439 state_ = IS_OPEN; | 445 state_ = IS_OPEN; |
| 440 TraceSendThrottlingState(); | 446 TraceSendThrottlingState(); |
| 441 | 447 |
| 442 // Set all pending options if any. | 448 // Set all pending options if any. |
| 443 for (int i = 0; i < P2P_SOCKET_OPT_MAX; ++i) { | 449 for (int i = 0; i < P2P_SOCKET_OPT_MAX; ++i) { |
| 444 if (options_[i] != kDefaultNonSetOptionValue) | 450 if (options_[i] != kDefaultNonSetOptionValue) |
| 445 DoSetOption(static_cast<P2PSocketOption> (i), options_[i]); | 451 DoSetOption(static_cast<P2PSocketOption> (i), options_[i]); |
| 446 } | 452 } |
| 447 | 453 |
| 448 SignalAddressReady(this, local_address_); | 454 SignalAddressReady(this, local_address_); |
| 449 if (IsTcpClientSocket(type_)) | 455 if (IsTcpClientSocket(type_)) { |
| 450 SignalConnect(this); | 456 SignalConnect(this); |
| 457 // If remote address is unresolved, set resolved remote IP address received |
| 458 // in the callback. This address will be used while sending the packets |
| 459 // over the network. |
| 460 if (remote_address_.IsUnresolvedIP()) { |
| 461 talk_base::SocketAddress jingle_socket_address; |
| 462 if (!jingle_glue::IPEndPointToSocketAddress( |
| 463 remote_address, &jingle_socket_address)) { |
| 464 NOTREACHED(); |
| 465 } |
| 466 // Set only the IP address. |
| 467 remote_address_.SetResolvedIP(jingle_socket_address.ipaddr()); |
| 468 } |
| 469 } |
| 451 } | 470 } |
| 452 | 471 |
| 453 void IpcPacketSocket::OnIncomingTcpConnection( | 472 void IpcPacketSocket::OnIncomingTcpConnection( |
| 454 const net::IPEndPoint& address, | 473 const net::IPEndPoint& address, |
| 455 P2PSocketClient* client) { | 474 P2PSocketClient* client) { |
| 456 DCHECK_EQ(base::MessageLoop::current(), message_loop_); | 475 DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
| 457 | 476 |
| 458 scoped_ptr<IpcPacketSocket> socket(new IpcPacketSocket()); | 477 scoped_ptr<IpcPacketSocket> socket(new IpcPacketSocket()); |
| 459 | 478 |
| 460 talk_base::SocketAddress remote_address; | 479 talk_base::SocketAddress remote_address; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 } | 666 } |
| 648 | 667 |
| 649 talk_base::AsyncResolverInterface* | 668 talk_base::AsyncResolverInterface* |
| 650 IpcPacketSocketFactory::CreateAsyncResolver() { | 669 IpcPacketSocketFactory::CreateAsyncResolver() { |
| 651 scoped_ptr<AsyncAddressResolverImpl> resolver( | 670 scoped_ptr<AsyncAddressResolverImpl> resolver( |
| 652 new AsyncAddressResolverImpl(socket_dispatcher_)); | 671 new AsyncAddressResolverImpl(socket_dispatcher_)); |
| 653 return resolver.release(); | 672 return resolver.release(); |
| 654 } | 673 } |
| 655 | 674 |
| 656 } // namespace content | 675 } // namespace content |
| OLD | NEW |