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