| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <list> | 10 #include <list> |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 InFlightPacketRecord(uint64_t packet_id, size_t packet_size) | 86 InFlightPacketRecord(uint64_t packet_id, size_t packet_size) |
| 87 : packet_id(packet_id), packet_size(packet_size) {} | 87 : packet_id(packet_id), packet_size(packet_size) {} |
| 88 | 88 |
| 89 uint64_t packet_id; | 89 uint64_t packet_id; |
| 90 size_t packet_size; | 90 size_t packet_size; |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 typedef std::list<InFlightPacketRecord> InFlightPacketList; | 93 typedef std::list<InFlightPacketRecord> InFlightPacketList; |
| 94 | 94 |
| 95 // Always takes ownership of client even if initialization fails. | 95 // Always takes ownership of client even if initialization fails. |
| 96 bool Init(P2PSocketType type, P2PSocketClientImpl* client, | 96 bool Init(P2PSocketType type, |
| 97 P2PSocketClientImpl* client, |
| 97 const rtc::SocketAddress& local_address, | 98 const rtc::SocketAddress& local_address, |
| 99 uint16_t min_port, |
| 100 uint16_t max_port, |
| 98 const rtc::SocketAddress& remote_address); | 101 const rtc::SocketAddress& remote_address); |
| 99 | 102 |
| 100 // rtc::AsyncPacketSocket interface. | 103 // rtc::AsyncPacketSocket interface. |
| 101 rtc::SocketAddress GetLocalAddress() const override; | 104 rtc::SocketAddress GetLocalAddress() const override; |
| 102 rtc::SocketAddress GetRemoteAddress() const override; | 105 rtc::SocketAddress GetRemoteAddress() const override; |
| 103 int Send(const void* pv, | 106 int Send(const void* pv, |
| 104 size_t cb, | 107 size_t cb, |
| 105 const rtc::PacketOptions& options) override; | 108 const rtc::PacketOptions& options) override; |
| 106 int SendTo(const void* pv, | 109 int SendTo(const void* pv, |
| 107 size_t cb, | 110 size_t cb, |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 &send_buffer_size); | 288 &send_buffer_size); |
| 286 | 289 |
| 287 if (send_buffer_size > 0) { | 290 if (send_buffer_size > 0) { |
| 288 send_bytes_available_ = send_buffer_size; | 291 send_bytes_available_ = send_buffer_size; |
| 289 } | 292 } |
| 290 } | 293 } |
| 291 | 294 |
| 292 bool IpcPacketSocket::Init(P2PSocketType type, | 295 bool IpcPacketSocket::Init(P2PSocketType type, |
| 293 P2PSocketClientImpl* client, | 296 P2PSocketClientImpl* client, |
| 294 const rtc::SocketAddress& local_address, | 297 const rtc::SocketAddress& local_address, |
| 298 uint16_t min_port, |
| 299 uint16_t max_port, |
| 295 const rtc::SocketAddress& remote_address) { | 300 const rtc::SocketAddress& remote_address) { |
| 296 DCHECK_EQ(base::MessageLoop::current(), message_loop_); | 301 DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
| 297 DCHECK_EQ(state_, IS_UNINITIALIZED); | 302 DCHECK_EQ(state_, IS_UNINITIALIZED); |
| 298 | 303 |
| 299 type_ = type; | 304 type_ = type; |
| 300 client_ = client; | 305 client_ = client; |
| 301 local_address_ = local_address; | 306 local_address_ = local_address; |
| 302 remote_address_ = remote_address; | 307 remote_address_ = remote_address; |
| 303 state_ = IS_OPENING; | 308 state_ = IS_OPENING; |
| 304 | 309 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 325 return false; | 330 return false; |
| 326 } | 331 } |
| 327 } | 332 } |
| 328 } | 333 } |
| 329 | 334 |
| 330 // We need to send both resolved and unresolved address in Init. Unresolved | 335 // We need to send both resolved and unresolved address in Init. Unresolved |
| 331 // address will be used in case of TLS for certificate hostname matching. | 336 // address will be used in case of TLS for certificate hostname matching. |
| 332 // Certificate will be tied to domain name not to IP address. | 337 // Certificate will be tied to domain name not to IP address. |
| 333 P2PHostAndIPEndPoint remote_info(remote_address.hostname(), remote_endpoint); | 338 P2PHostAndIPEndPoint remote_info(remote_address.hostname(), remote_endpoint); |
| 334 | 339 |
| 335 client->Init(type, local_endpoint, remote_info, this); | 340 client->Init(type, local_endpoint, min_port, max_port, remote_info, this); |
| 336 | 341 |
| 337 return true; | 342 return true; |
| 338 } | 343 } |
| 339 | 344 |
| 340 void IpcPacketSocket::InitAcceptedTcp( | 345 void IpcPacketSocket::InitAcceptedTcp( |
| 341 P2PSocketClient* client, | 346 P2PSocketClient* client, |
| 342 const rtc::SocketAddress& local_address, | 347 const rtc::SocketAddress& local_address, |
| 343 const rtc::SocketAddress& remote_address) { | 348 const rtc::SocketAddress& remote_address) { |
| 344 DCHECK_EQ(base::MessageLoop::current(), message_loop_); | 349 DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
| 345 DCHECK_EQ(state_, IS_UNINITIALIZED); | 350 DCHECK_EQ(state_, IS_UNINITIALIZED); |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 : socket_dispatcher_(socket_dispatcher) { | 741 : socket_dispatcher_(socket_dispatcher) { |
| 737 } | 742 } |
| 738 | 743 |
| 739 IpcPacketSocketFactory::~IpcPacketSocketFactory() { | 744 IpcPacketSocketFactory::~IpcPacketSocketFactory() { |
| 740 } | 745 } |
| 741 | 746 |
| 742 rtc::AsyncPacketSocket* IpcPacketSocketFactory::CreateUdpSocket( | 747 rtc::AsyncPacketSocket* IpcPacketSocketFactory::CreateUdpSocket( |
| 743 const rtc::SocketAddress& local_address, | 748 const rtc::SocketAddress& local_address, |
| 744 uint16_t min_port, | 749 uint16_t min_port, |
| 745 uint16_t max_port) { | 750 uint16_t max_port) { |
| 746 rtc::SocketAddress crome_address; | |
| 747 P2PSocketClientImpl* socket_client = | 751 P2PSocketClientImpl* socket_client = |
| 748 new P2PSocketClientImpl(socket_dispatcher_); | 752 new P2PSocketClientImpl(socket_dispatcher_); |
| 749 std::unique_ptr<IpcPacketSocket> socket(new IpcPacketSocket()); | 753 std::unique_ptr<IpcPacketSocket> socket(new IpcPacketSocket()); |
| 750 // TODO(sergeyu): Respect local_address and port limits here (need | 754 if (!socket->Init(P2P_SOCKET_UDP, socket_client, local_address, min_port, |
| 751 // to pass them over IPC channel to the browser). | 755 max_port, rtc::SocketAddress())) { |
| 752 if (!socket->Init(P2P_SOCKET_UDP, socket_client, | 756 return nullptr; |
| 753 local_address, rtc::SocketAddress())) { | |
| 754 return NULL; | |
| 755 } | 757 } |
| 756 return socket.release(); | 758 return socket.release(); |
| 757 } | 759 } |
| 758 | 760 |
| 759 rtc::AsyncPacketSocket* IpcPacketSocketFactory::CreateServerTcpSocket( | 761 rtc::AsyncPacketSocket* IpcPacketSocketFactory::CreateServerTcpSocket( |
| 760 const rtc::SocketAddress& local_address, | 762 const rtc::SocketAddress& local_address, |
| 761 uint16_t min_port, | 763 uint16_t min_port, |
| 762 uint16_t max_port, | 764 uint16_t max_port, |
| 763 int opts) { | 765 int opts) { |
| 764 // TODO(sergeyu): Implement SSL support. | 766 // TODO(sergeyu): Implement SSL support. |
| 765 if (opts & rtc::PacketSocketFactory::OPT_SSLTCP) | 767 if (opts & rtc::PacketSocketFactory::OPT_SSLTCP) |
| 766 return NULL; | 768 return NULL; |
| 767 | 769 |
| 768 P2PSocketType type = (opts & rtc::PacketSocketFactory::OPT_STUN) ? | 770 P2PSocketType type = (opts & rtc::PacketSocketFactory::OPT_STUN) ? |
| 769 P2P_SOCKET_STUN_TCP_SERVER : P2P_SOCKET_TCP_SERVER; | 771 P2P_SOCKET_STUN_TCP_SERVER : P2P_SOCKET_TCP_SERVER; |
| 770 P2PSocketClientImpl* socket_client = | 772 P2PSocketClientImpl* socket_client = |
| 771 new P2PSocketClientImpl(socket_dispatcher_); | 773 new P2PSocketClientImpl(socket_dispatcher_); |
| 772 std::unique_ptr<IpcPacketSocket> socket(new IpcPacketSocket()); | 774 std::unique_ptr<IpcPacketSocket> socket(new IpcPacketSocket()); |
| 773 if (!socket->Init(type, socket_client, local_address, | 775 if (!socket->Init(type, socket_client, local_address, min_port, max_port, |
| 774 rtc::SocketAddress())) { | 776 rtc::SocketAddress())) { |
| 775 return NULL; | 777 return NULL; |
| 776 } | 778 } |
| 777 return socket.release(); | 779 return socket.release(); |
| 778 } | 780 } |
| 779 | 781 |
| 780 rtc::AsyncPacketSocket* IpcPacketSocketFactory::CreateClientTcpSocket( | 782 rtc::AsyncPacketSocket* IpcPacketSocketFactory::CreateClientTcpSocket( |
| 781 const rtc::SocketAddress& local_address, | 783 const rtc::SocketAddress& local_address, |
| 782 const rtc::SocketAddress& remote_address, | 784 const rtc::SocketAddress& remote_address, |
| 783 const rtc::ProxyInfo& proxy_info, | 785 const rtc::ProxyInfo& proxy_info, |
| 784 const std::string& user_agent, int opts) { | 786 const std::string& user_agent, int opts) { |
| 785 P2PSocketType type; | 787 P2PSocketType type; |
| 786 if (opts & rtc::PacketSocketFactory::OPT_SSLTCP) { | 788 if (opts & rtc::PacketSocketFactory::OPT_SSLTCP) { |
| 787 type = (opts & rtc::PacketSocketFactory::OPT_STUN) ? | 789 type = (opts & rtc::PacketSocketFactory::OPT_STUN) ? |
| 788 P2P_SOCKET_STUN_SSLTCP_CLIENT : P2P_SOCKET_SSLTCP_CLIENT; | 790 P2P_SOCKET_STUN_SSLTCP_CLIENT : P2P_SOCKET_SSLTCP_CLIENT; |
| 789 } else if (opts & rtc::PacketSocketFactory::OPT_TLS) { | 791 } else if (opts & rtc::PacketSocketFactory::OPT_TLS) { |
| 790 type = (opts & rtc::PacketSocketFactory::OPT_STUN) ? | 792 type = (opts & rtc::PacketSocketFactory::OPT_STUN) ? |
| 791 P2P_SOCKET_STUN_TLS_CLIENT : P2P_SOCKET_TLS_CLIENT; | 793 P2P_SOCKET_STUN_TLS_CLIENT : P2P_SOCKET_TLS_CLIENT; |
| 792 } else { | 794 } else { |
| 793 type = (opts & rtc::PacketSocketFactory::OPT_STUN) ? | 795 type = (opts & rtc::PacketSocketFactory::OPT_STUN) ? |
| 794 P2P_SOCKET_STUN_TCP_CLIENT : P2P_SOCKET_TCP_CLIENT; | 796 P2P_SOCKET_STUN_TCP_CLIENT : P2P_SOCKET_TCP_CLIENT; |
| 795 } | 797 } |
| 796 P2PSocketClientImpl* socket_client = | 798 P2PSocketClientImpl* socket_client = |
| 797 new P2PSocketClientImpl(socket_dispatcher_); | 799 new P2PSocketClientImpl(socket_dispatcher_); |
| 798 std::unique_ptr<IpcPacketSocket> socket(new IpcPacketSocket()); | 800 std::unique_ptr<IpcPacketSocket> socket(new IpcPacketSocket()); |
| 799 if (!socket->Init(type, socket_client, local_address, remote_address)) | 801 if (!socket->Init(type, socket_client, local_address, 0, 0, remote_address)) |
| 800 return NULL; | 802 return NULL; |
| 801 return socket.release(); | 803 return socket.release(); |
| 802 } | 804 } |
| 803 | 805 |
| 804 rtc::AsyncResolverInterface* | 806 rtc::AsyncResolverInterface* |
| 805 IpcPacketSocketFactory::CreateAsyncResolver() { | 807 IpcPacketSocketFactory::CreateAsyncResolver() { |
| 806 std::unique_ptr<AsyncAddressResolverImpl> resolver( | 808 std::unique_ptr<AsyncAddressResolverImpl> resolver( |
| 807 new AsyncAddressResolverImpl(socket_dispatcher_)); | 809 new AsyncAddressResolverImpl(socket_dispatcher_)); |
| 808 return resolver.release(); | 810 return resolver.release(); |
| 809 } | 811 } |
| 810 | 812 |
| 811 } // namespace content | 813 } // namespace content |
| OLD | NEW |