| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_UDP_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_UDP_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_UDP_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_UDP_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <deque> | 11 #include <deque> |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <set> | 13 #include <set> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/callback.h" |
| 16 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
| 17 #include "base/macros.h" | 18 #include "base/macros.h" |
| 18 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 19 #include "base/message_loop/message_loop.h" | 20 #include "base/message_loop/message_loop.h" |
| 20 #include "content/browser/renderer_host/p2p/socket_host.h" | 21 #include "content/browser/renderer_host/p2p/socket_host.h" |
| 21 #include "content/common/content_export.h" | 22 #include "content/common/content_export.h" |
| 22 #include "content/common/p2p_socket_type.h" | 23 #include "content/common/p2p_socket_type.h" |
| 23 #include "net/base/ip_endpoint.h" | 24 #include "net/base/ip_endpoint.h" |
| 24 #include "net/udp/diff_serv_code_point.h" | 25 #include "net/udp/diff_serv_code_point.h" |
| 25 #include "net/udp/udp_server_socket.h" | 26 #include "net/udp/udp_server_socket.h" |
| 26 #include "third_party/webrtc/base/asyncpacketsocket.h" | 27 #include "third_party/webrtc/base/asyncpacketsocket.h" |
| 27 | 28 |
| 28 namespace content { | 29 namespace content { |
| 29 | 30 |
| 30 class P2PMessageThrottler; | 31 class P2PMessageThrottler; |
| 31 | 32 |
| 32 class CONTENT_EXPORT P2PSocketHostUdp : public P2PSocketHost { | 33 class CONTENT_EXPORT P2PSocketHostUdp : public P2PSocketHost { |
| 33 public: | 34 public: |
| 35 typedef base::Callback<std::unique_ptr<net::DatagramServerSocket>()> |
| 36 DatagramServerSocketFactory; |
| 37 P2PSocketHostUdp(IPC::Sender* message_sender, |
| 38 int socket_id, |
| 39 P2PMessageThrottler* throttler, |
| 40 const DatagramServerSocketFactory& socket_factory); |
| 34 P2PSocketHostUdp(IPC::Sender* message_sender, | 41 P2PSocketHostUdp(IPC::Sender* message_sender, |
| 35 int socket_id, | 42 int socket_id, |
| 36 P2PMessageThrottler* throttler); | 43 P2PMessageThrottler* throttler); |
| 37 ~P2PSocketHostUdp() override; | 44 ~P2PSocketHostUdp() override; |
| 38 | 45 |
| 39 // P2PSocketHost overrides. | 46 // P2PSocketHost overrides. |
| 40 bool Init(const net::IPEndPoint& local_address, | 47 bool Init(const net::IPEndPoint& local_address, |
| 48 uint16_t min_port, |
| 49 uint16_t max_port, |
| 41 const P2PHostAndIPEndPoint& remote_address) override; | 50 const P2PHostAndIPEndPoint& remote_address) override; |
| 42 void Send(const net::IPEndPoint& to, | 51 void Send(const net::IPEndPoint& to, |
| 43 const std::vector<char>& data, | 52 const std::vector<char>& data, |
| 44 const rtc::PacketOptions& options, | 53 const rtc::PacketOptions& options, |
| 45 uint64_t packet_id) override; | 54 uint64_t packet_id) override; |
| 46 P2PSocketHost* AcceptIncomingTcpConnection( | 55 P2PSocketHost* AcceptIncomingTcpConnection( |
| 47 const net::IPEndPoint& remote_address, | 56 const net::IPEndPoint& remote_address, |
| 48 int id) override; | 57 int id) override; |
| 49 bool SetOption(P2PSocketOption option, int value) override; | 58 bool SetOption(P2PSocketOption option, int value) override; |
| 50 | 59 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 77 | 86 |
| 78 void DoSend(const PendingPacket& packet); | 87 void DoSend(const PendingPacket& packet); |
| 79 void OnSend(uint64_t packet_id, | 88 void OnSend(uint64_t packet_id, |
| 80 int32_t transport_sequence_number, | 89 int32_t transport_sequence_number, |
| 81 base::TimeTicks send_time, | 90 base::TimeTicks send_time, |
| 82 int result); | 91 int result); |
| 83 void HandleSendResult(uint64_t packet_id, | 92 void HandleSendResult(uint64_t packet_id, |
| 84 int32_t transport_sequence_number, | 93 int32_t transport_sequence_number, |
| 85 base::TimeTicks send_time, | 94 base::TimeTicks send_time, |
| 86 int result); | 95 int result); |
| 96 static std::unique_ptr<net::DatagramServerSocket> DefaultSocketFactory(); |
| 87 | 97 |
| 88 std::unique_ptr<net::DatagramServerSocket> socket_; | 98 std::unique_ptr<net::DatagramServerSocket> socket_; |
| 89 scoped_refptr<net::IOBuffer> recv_buffer_; | 99 scoped_refptr<net::IOBuffer> recv_buffer_; |
| 90 net::IPEndPoint recv_address_; | 100 net::IPEndPoint recv_address_; |
| 91 | 101 |
| 92 std::deque<PendingPacket> send_queue_; | 102 std::deque<PendingPacket> send_queue_; |
| 93 bool send_pending_; | 103 bool send_pending_; |
| 94 net::DiffServCodePoint last_dscp_; | 104 net::DiffServCodePoint last_dscp_; |
| 95 | 105 |
| 96 // Set of peer for which we have received STUN binding request or | 106 // Set of peer for which we have received STUN binding request or |
| 97 // response or relay allocation request or response. | 107 // response or relay allocation request or response. |
| 98 ConnectedPeerSet connected_peers_; | 108 ConnectedPeerSet connected_peers_; |
| 99 P2PMessageThrottler* throttler_; | 109 P2PMessageThrottler* throttler_; |
| 100 | 110 |
| 101 // Keep track of the send socket buffer size under experiment. | 111 // Keep track of the send socket buffer size under experiment. |
| 102 size_t send_buffer_size_; | 112 size_t send_buffer_size_; |
| 103 | 113 |
| 114 // Callback object that returns a new socket when invoked. |
| 115 DatagramServerSocketFactory socket_factory_; |
| 116 |
| 104 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostUdp); | 117 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostUdp); |
| 105 }; | 118 }; |
| 106 | 119 |
| 107 } // namespace content | 120 } // namespace content |
| 108 | 121 |
| 109 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_UDP_H_ | 122 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_UDP_H_ |
| OLD | NEW |