Chromium Code Reviews| 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 <deque> | 8 #include <deque> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 const P2PHostAndIPEndPoint& remote_address) override; | 36 const P2PHostAndIPEndPoint& remote_address) override; |
| 37 void Send(const net::IPEndPoint& to, | 37 void Send(const net::IPEndPoint& to, |
| 38 const std::vector<char>& data, | 38 const std::vector<char>& data, |
| 39 const rtc::PacketOptions& options, | 39 const rtc::PacketOptions& options, |
| 40 uint64 packet_id) override; | 40 uint64 packet_id) override; |
| 41 P2PSocketHost* AcceptIncomingTcpConnection( | 41 P2PSocketHost* AcceptIncomingTcpConnection( |
| 42 const net::IPEndPoint& remote_address, | 42 const net::IPEndPoint& remote_address, |
| 43 int id) override; | 43 int id) override; |
| 44 bool SetOption(P2PSocketOption option, int value) override; | 44 bool SetOption(P2PSocketOption option, int value) override; |
| 45 | 45 |
| 46 // Helper functions to hijack upper 32 bits for latency calculation. | |
| 47 // PackCallRecord will return a "CallRecord". A "CallRecord" has its lower 32 | |
| 48 // bits as the lower 32 bits of packet id (without the random prefix) and its | |
| 49 // higher 32 bits as the lower 32 bits of tick count when the packet arrives | |
| 50 // at Send(). | |
| 51 static uint64 PackCallRecord(const uint64 packet_id, const uint64 ticks_now); | |
|
Alexei Svitkine (slow)
2014/11/04 15:17:50
Nit: Usually primitive params aren't marked const.
guoweis2
2014/11/07 22:18:19
Code removed.
| |
| 52 // |ticks_diff| contains the difference between the time when | |
| 53 // |packed_call_record| is packed and |ticks_now|. | |
| 54 static void UnpackCallRecord(const uint64 packed_call_record, | |
| 55 const uint64 random_socket_id_prefix, | |
| 56 const uint64 ticks_now, | |
| 57 uint64* packet_id, | |
| 58 uint64* ticks_diff); | |
| 59 | |
| 46 private: | 60 private: |
| 47 friend class P2PSocketHostUdpTest; | 61 friend class P2PSocketHostUdpTest; |
| 48 | 62 |
| 49 typedef std::set<net::IPEndPoint> ConnectedPeerSet; | 63 typedef std::set<net::IPEndPoint> ConnectedPeerSet; |
| 50 | 64 |
| 51 struct PendingPacket { | 65 struct PendingPacket { |
| 52 PendingPacket(const net::IPEndPoint& to, | 66 PendingPacket(const net::IPEndPoint& to, |
| 53 const std::vector<char>& content, | 67 const std::vector<char>& content, |
| 54 const rtc::PacketOptions& options, | 68 const rtc::PacketOptions& options, |
| 55 uint64 id); | 69 uint64 id); |
| 56 ~PendingPacket(); | 70 ~PendingPacket(); |
| 57 net::IPEndPoint to; | 71 net::IPEndPoint to; |
| 58 scoped_refptr<net::IOBuffer> data; | 72 scoped_refptr<net::IOBuffer> data; |
| 59 int size; | 73 int size; |
| 60 rtc::PacketOptions packet_options; | 74 rtc::PacketOptions packet_options; |
| 61 uint64 id; | 75 uint64 id; |
| 62 }; | 76 }; |
| 63 | 77 |
| 64 void OnError(); | 78 void OnError(); |
| 65 | 79 |
| 80 void SetSendBufferSize(); | |
| 81 | |
| 66 void DoRead(); | 82 void DoRead(); |
| 67 void OnRecv(int result); | 83 void OnRecv(int result); |
| 68 void HandleReadResult(int result); | 84 void HandleReadResult(int result); |
| 69 | 85 |
| 70 void DoSend(const PendingPacket& packet); | 86 void DoSend(const PendingPacket& packet); |
| 71 void OnSend(uint64 packet_id, int result); | 87 void OnSend(uint64 packet_id, int result); |
| 72 void HandleSendResult(uint64 packet_id, int result); | 88 void HandleSendResult(uint64 packet_id, int result); |
| 73 | 89 |
| 74 scoped_ptr<net::DatagramServerSocket> socket_; | 90 scoped_ptr<net::DatagramServerSocket> socket_; |
| 75 scoped_refptr<net::IOBuffer> recv_buffer_; | 91 scoped_refptr<net::IOBuffer> recv_buffer_; |
| 76 net::IPEndPoint recv_address_; | 92 net::IPEndPoint recv_address_; |
| 77 | 93 |
| 78 std::deque<PendingPacket> send_queue_; | 94 std::deque<PendingPacket> send_queue_; |
| 79 bool send_pending_; | 95 bool send_pending_; |
| 80 net::DiffServCodePoint last_dscp_; | 96 net::DiffServCodePoint last_dscp_; |
| 81 | 97 |
| 98 // When the renderer sends the packet through IPC, an unique packet_id is | |
| 99 // stamped at each packet to allow tracing infrastructure to uniquely identify | |
| 100 // each packet. The packet id is always constructed as a random number at | |
| 101 // upper 32 bits and a sequence number starting from 0 at lower 32 bits. The | |
| 102 // packet id is also sent to socket::SendTo as a callback parameter in case | |
| 103 // when the socket can't send it synchronously. The callback only allows an | |
| 104 // int64 as a parameter. To allow us to track the latency across the | |
| 105 // asynchronous socket::SendTo, we are hijacking the higher 32 bits for | |
| 106 // latency calculation. The |random_socket_id_prefix| is kept here so we could | |
| 107 // reconstruct the correct packet id. | |
| 108 uint64 random_socket_id_prefix_; | |
|
Alexei Svitkine (slow)
2014/11/04 15:17:50
Nit: I think for new code, uint64_t is preferred (
guoweis2
2014/11/07 22:18:19
Code removed.
| |
| 109 | |
| 82 // Set of peer for which we have received STUN binding request or | 110 // Set of peer for which we have received STUN binding request or |
| 83 // response or relay allocation request or response. | 111 // response or relay allocation request or response. |
| 84 ConnectedPeerSet connected_peers_; | 112 ConnectedPeerSet connected_peers_; |
| 85 P2PMessageThrottler* throttler_; | 113 P2PMessageThrottler* throttler_; |
| 86 | 114 |
| 87 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostUdp); | 115 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostUdp); |
| 88 }; | 116 }; |
| 89 | 117 |
| 90 } // namespace content | 118 } // namespace content |
| 91 | 119 |
| 92 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_UDP_H_ | 120 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_UDP_H_ |
| OLD | NEW |