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_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_H_ |
7 | 7 |
8 #include "content/common/content_export.h" | 8 #include "content/common/content_export.h" |
9 #include "content/common/p2p_socket_type.h" | 9 #include "content/common/p2p_socket_type.h" |
10 #include "net/base/ip_endpoint.h" | 10 #include "net/base/ip_endpoint.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 // This method can handle only RTP packet, otherwise this method must not be | 30 // This method can handle only RTP packet, otherwise this method must not be |
31 // called. It will try to do, 1. update absolute send time extension header | 31 // called. It will try to do, 1. update absolute send time extension header |
32 // if present with current time and 2. update HMAC in RTP packet. | 32 // if present with current time and 2. update HMAC in RTP packet. |
33 // If abs_send_time is 0, ApplyPacketOption will get current time from system. | 33 // If abs_send_time is 0, ApplyPacketOption will get current time from system. |
34 CONTENT_EXPORT bool ApplyPacketOptions(char* data, int length, | 34 CONTENT_EXPORT bool ApplyPacketOptions(char* data, int length, |
35 const talk_base::PacketOptions& options, | 35 const talk_base::PacketOptions& options, |
36 uint32 abs_send_time); | 36 uint32 abs_send_time); |
37 | 37 |
38 // Helper method which finds RTP ofset and length if the packet is encapsulated | 38 // Helper method which finds RTP ofset and length if the packet is encapsulated |
39 // in a TURN Channel Message or TURN Send Indication message. | 39 // in a TURN Channel Message or TURN Send Indication message. |
40 CONTENT_EXPORT bool GetRtpPacketStartPositionAndLength(char* data, int length, | 40 CONTENT_EXPORT bool GetRtpPacketStartPositionAndLength(const char* data, |
| 41 int length, |
41 int* rtp_start_pos, | 42 int* rtp_start_pos, |
42 int* rtp_packet_length); | 43 int* rtp_packet_length); |
43 // Helper method which updates absoulute send time extension if present. | 44 // Helper method which updates absoulute send time extension if present. |
44 CONTENT_EXPORT bool UpdateRtpAbsSendTimeExtn(char* rtp, int length, | 45 CONTENT_EXPORT bool UpdateRtpAbsSendTimeExtn(char* rtp, int length, |
45 int extension_id, | 46 int extension_id, |
46 uint32 abs_send_time); | 47 uint32 abs_send_time); |
47 | 48 |
48 } // packet_processing_helpers | 49 } // packet_processing_helpers |
49 | 50 |
50 // Base class for P2P sockets. | 51 // Base class for P2P sockets. |
51 class CONTENT_EXPORT P2PSocketHost { | 52 class CONTENT_EXPORT P2PSocketHost { |
52 public: | 53 public: |
53 static const int kStunHeaderSize = 20; | 54 static const int kStunHeaderSize = 20; |
54 // Creates P2PSocketHost of the specific type. | 55 // Creates P2PSocketHost of the specific type. |
55 static P2PSocketHost* Create(IPC::Sender* message_sender, | 56 static P2PSocketHost* Create(IPC::Sender* message_sender, |
56 int id, P2PSocketType type, | 57 int socket_id, |
| 58 int render_process_host_id, |
| 59 P2PSocketType type, |
57 net::URLRequestContextGetter* url_context, | 60 net::URLRequestContextGetter* url_context, |
58 P2PMessageThrottler* throttler); | 61 P2PMessageThrottler* throttler); |
59 | 62 |
60 virtual ~P2PSocketHost(); | 63 virtual ~P2PSocketHost(); |
61 | 64 |
62 // Initalizes the socket. Returns false when initiazations fails. | 65 // Initalizes the socket. Returns false when initiazations fails. |
63 virtual bool Init(const net::IPEndPoint& local_address, | 66 virtual bool Init(const net::IPEndPoint& local_address, |
64 const P2PHostAndIPEndPoint& remote_address) = 0; | 67 const P2PHostAndIPEndPoint& remote_address) = 0; |
65 | 68 |
66 // Sends |data| on the socket to |to|. | 69 // Sends |data| on the socket to |to|. |
67 virtual void Send(const net::IPEndPoint& to, | 70 virtual void Send(const net::IPEndPoint& to, |
68 const std::vector<char>& data, | 71 const std::vector<char>& data, |
69 const talk_base::PacketOptions& options, | 72 const talk_base::PacketOptions& options, |
70 uint64 packet_id) = 0; | 73 uint64 packet_id) = 0; |
71 | 74 |
72 virtual P2PSocketHost* AcceptIncomingTcpConnection( | 75 virtual P2PSocketHost* AcceptIncomingTcpConnection( |
73 const net::IPEndPoint& remote_address, int id) = 0; | 76 const net::IPEndPoint& remote_address, int id) = 0; |
74 | 77 |
75 virtual bool SetOption(P2PSocketOption option, int value) = 0; | 78 virtual bool SetOption(P2PSocketOption option, int value) = 0; |
76 | 79 |
| 80 void StartRtpDump(bool incoming, bool outgoing); |
| 81 void StopRtpDump(bool incoming, bool outgoing); |
| 82 |
77 protected: | 83 protected: |
78 friend class P2PSocketHostTcpTestBase; | 84 friend class P2PSocketHostTcpTestBase; |
79 | 85 |
80 // TODO(mallinath) - Remove this below enum and use one defined in | 86 // TODO(mallinath) - Remove this below enum and use one defined in |
81 // libjingle/souce/talk/p2p/base/stun.h | 87 // libjingle/souce/talk/p2p/base/stun.h |
82 enum StunMessageType { | 88 enum StunMessageType { |
83 STUN_BINDING_REQUEST = 0x0001, | 89 STUN_BINDING_REQUEST = 0x0001, |
84 STUN_BINDING_RESPONSE = 0x0101, | 90 STUN_BINDING_RESPONSE = 0x0101, |
85 STUN_BINDING_ERROR_RESPONSE = 0x0111, | 91 STUN_BINDING_ERROR_RESPONSE = 0x0111, |
86 STUN_SHARED_SECRET_REQUEST = 0x0002, | 92 STUN_SHARED_SECRET_REQUEST = 0x0002, |
(...skipping 17 matching lines...) Expand all Loading... |
104 }; | 110 }; |
105 | 111 |
106 enum State { | 112 enum State { |
107 STATE_UNINITIALIZED, | 113 STATE_UNINITIALIZED, |
108 STATE_CONNECTING, | 114 STATE_CONNECTING, |
109 STATE_TLS_CONNECTING, | 115 STATE_TLS_CONNECTING, |
110 STATE_OPEN, | 116 STATE_OPEN, |
111 STATE_ERROR, | 117 STATE_ERROR, |
112 }; | 118 }; |
113 | 119 |
114 P2PSocketHost(IPC::Sender* message_sender, int id); | 120 P2PSocketHost(IPC::Sender* message_sender, |
| 121 int socket_id, |
| 122 int render_process_host_id); |
115 | 123 |
116 // Verifies that the packet |data| has a valid STUN header. In case | 124 // Verifies that the packet |data| has a valid STUN header. In case |
117 // of success stores type of the message in |type|. | 125 // of success stores type of the message in |type|. |
118 static bool GetStunPacketType(const char* data, int data_size, | 126 static bool GetStunPacketType(const char* data, int data_size, |
119 StunMessageType* type); | 127 StunMessageType* type); |
120 static bool IsRequestOrResponse(StunMessageType type); | 128 static bool IsRequestOrResponse(StunMessageType type); |
121 | 129 |
| 130 static void DumpRtpPacketOnUIThread(scoped_ptr<char[]> packet_header, |
| 131 size_t header_length, |
| 132 size_t packet_length, |
| 133 bool incoming, |
| 134 int render_process_host_id); |
| 135 |
| 136 // Calls RenderProcessHostImpl::OnRtpPacket to record the RTP header. |
| 137 void DumpRtpPacket(const char* packet, size_t length, bool incoming); |
| 138 |
122 IPC::Sender* message_sender_; | 139 IPC::Sender* message_sender_; |
123 int id_; | 140 int id_; |
| 141 int render_process_host_id_; |
124 State state_; | 142 State state_; |
| 143 bool dump_incoming_rtp_packet_; |
| 144 bool dump_outgoing_rtp_packet_; |
125 | 145 |
126 DISALLOW_COPY_AND_ASSIGN(P2PSocketHost); | 146 DISALLOW_COPY_AND_ASSIGN(P2PSocketHost); |
127 }; | 147 }; |
128 | 148 |
129 } // namespace content | 149 } // namespace content |
130 | 150 |
131 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_H_ | 151 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_H_ |
OLD | NEW |