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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 InFlightPacketRecord(uint64_t packet_id, size_t packet_size) | 87 InFlightPacketRecord(uint64_t packet_id, size_t packet_size) |
88 : packet_id(packet_id), packet_size(packet_size) {} | 88 : packet_id(packet_id), packet_size(packet_size) {} |
89 | 89 |
90 uint64_t packet_id; | 90 uint64_t packet_id; |
91 size_t packet_size; | 91 size_t packet_size; |
92 }; | 92 }; |
93 | 93 |
94 typedef std::list<InFlightPacketRecord> InFlightPacketList; | 94 typedef std::list<InFlightPacketRecord> InFlightPacketList; |
95 | 95 |
96 // Always takes ownership of client even if initialization fails. | 96 // Always takes ownership of client even if initialization fails. |
97 bool Init(P2PSocketType type, P2PSocketClientImpl* client, | 97 bool Init(P2PSocketType type, |
| 98 P2PSocketClientImpl* client, |
98 const rtc::SocketAddress& local_address, | 99 const rtc::SocketAddress& local_address, |
| 100 uint16_t min_port, |
| 101 uint16_t max_port, |
99 const rtc::SocketAddress& remote_address); | 102 const rtc::SocketAddress& remote_address); |
100 | 103 |
101 // rtc::AsyncPacketSocket interface. | 104 // rtc::AsyncPacketSocket interface. |
102 rtc::SocketAddress GetLocalAddress() const override; | 105 rtc::SocketAddress GetLocalAddress() const override; |
103 rtc::SocketAddress GetRemoteAddress() const override; | 106 rtc::SocketAddress GetRemoteAddress() const override; |
104 int Send(const void* pv, | 107 int Send(const void* pv, |
105 size_t cb, | 108 size_t cb, |
106 const rtc::PacketOptions& options) override; | 109 const rtc::PacketOptions& options) override; |
107 int SendTo(const void* pv, | 110 int SendTo(const void* pv, |
108 size_t cb, | 111 size_t cb, |
(...skipping 176 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(thread_checker_.CalledOnValidThread()); | 301 DCHECK(thread_checker_.CalledOnValidThread()); |
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(thread_checker_.CalledOnValidThread()); | 349 DCHECK(thread_checker_.CalledOnValidThread()); |
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 |