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/p2p_sockets.h" | 8 #include "content/common/p2p_sockets.h" |
9 | 9 |
| 10 #include "ipc/ipc_message.h" |
10 #include "net/base/ip_endpoint.h" | 11 #include "net/base/ip_endpoint.h" |
11 | 12 |
12 class P2PSocketsHost; | |
13 | |
14 // Base class for P2P sockets used by P2PSocketsHost. | 13 // Base class for P2P sockets used by P2PSocketsHost. |
15 class P2PSocketHost { | 14 class P2PSocketHost { |
16 public: | 15 public: |
17 // Creates P2PSocketHost of the specific type. | 16 // Creates P2PSocketHost of the specific type. |
18 static P2PSocketHost* Create(P2PSocketsHost* host, int routing_id, int id, | 17 static P2PSocketHost* Create(IPC::Message::Sender* message_sender, |
19 P2PSocketType type); | 18 int routing_id, int id, P2PSocketType type); |
20 | 19 |
21 virtual ~P2PSocketHost(); | 20 virtual ~P2PSocketHost(); |
22 | 21 |
23 // Initalizes the socket. Returns false when initiazations fails. | 22 // Initalizes the socket. Returns false when initiazations fails. |
24 virtual bool Init(const net::IPEndPoint& local_address) = 0; | 23 virtual bool Init(const net::IPEndPoint& local_address) = 0; |
25 | 24 |
26 // Sends |data| on the socket to |socket_address|. | 25 // Sends |data| on the socket to |to|. |
27 virtual void Send(const net::IPEndPoint& socket_address, | 26 virtual void Send(const net::IPEndPoint& to, |
28 const std::vector<char>& data) = 0; | 27 const std::vector<char>& data) = 0; |
29 | 28 |
30 protected: | 29 protected: |
31 P2PSocketHost(P2PSocketsHost* host, int routing_id, int id); | 30 enum StunMessageType { |
| 31 STUN_BINDING_REQUEST = 0x0001, |
| 32 STUN_BINDING_RESPONSE = 0x0101, |
| 33 STUN_BINDING_ERROR_RESPONSE = 0x0111, |
| 34 STUN_SHARED_SECRET_REQUEST = 0x0002, |
| 35 STUN_SHARED_SECRET_RESPONSE = 0x0102, |
| 36 STUN_SHARED_SECRET_ERROR_RESPONSE = 0x0112, |
| 37 STUN_ALLOCATE_REQUEST = 0x0003, |
| 38 STUN_ALLOCATE_RESPONSE = 0x0103, |
| 39 STUN_ALLOCATE_ERROR_RESPONSE = 0x0113, |
| 40 STUN_SEND_REQUEST = 0x0004, |
| 41 STUN_SEND_RESPONSE = 0x0104, |
| 42 STUN_SEND_ERROR_RESPONSE = 0x0114, |
| 43 STUN_DATA_INDICATION = 0x0115 |
| 44 }; |
32 | 45 |
33 P2PSocketsHost* host_; | 46 P2PSocketHost(IPC::Message::Sender* message_sender, int routing_id, int id); |
| 47 |
| 48 // Verifies that the packet |data| has a valid STUN header. In case |
| 49 // of success stores type of the message in |type|. |
| 50 bool GetStunPacketType(const char* data, int data_size, |
| 51 StunMessageType* type); |
| 52 |
| 53 IPC::Message::Sender* message_sender_; |
34 int routing_id_; | 54 int routing_id_; |
35 int id_; | 55 int id_; |
36 | 56 |
37 DISALLOW_COPY_AND_ASSIGN(P2PSocketHost); | 57 DISALLOW_COPY_AND_ASSIGN(P2PSocketHost); |
38 }; | 58 }; |
39 | 59 |
40 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_H_ | 60 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_H_ |
OLD | NEW |