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_TCP_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TCP_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TCP_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TCP_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
15 #include "content/browser/renderer_host/p2p/socket_host.h" | 15 #include "content/browser/renderer_host/p2p/socket_host.h" |
16 #include "content/common/p2p_sockets.h" | 16 #include "content/common/p2p_sockets.h" |
17 #include "net/base/completion_callback.h" | 17 #include "net/base/completion_callback.h" |
18 #include "net/base/ip_endpoint.h" | 18 #include "net/base/ip_endpoint.h" |
19 | 19 |
20 namespace net { | 20 namespace net { |
21 class DrainableIOBuffer; | 21 class DrainableIOBuffer; |
22 class GrowableIOBuffer; | 22 class GrowableIOBuffer; |
23 class StreamSocket; | 23 class StreamSocket; |
24 } // namespace net | 24 } // namespace net |
25 | 25 |
26 namespace content { | 26 namespace content { |
27 | 27 |
28 class CONTENT_EXPORT P2PSocketHostTcpBase : public P2PSocketHost { | 28 class CONTENT_EXPORT P2PSocketHostTcpBase : public P2PSocketHost { |
29 public: | 29 public: |
30 P2PSocketHostTcpBase(IPC::Sender* message_sender, int id); | 30 P2PSocketHostTcpBase(IPC::Sender* message_sender, int id, P2PSocketType type); |
31 virtual ~P2PSocketHostTcpBase(); | 31 virtual ~P2PSocketHostTcpBase(); |
32 | 32 |
33 bool InitAccepted(const net::IPEndPoint& remote_address, | 33 bool InitAccepted(const net::IPEndPoint& remote_address, |
34 net::StreamSocket* socket); | 34 net::StreamSocket* socket); |
35 | 35 |
36 // P2PSocketHost overrides. | 36 // P2PSocketHost overrides. |
37 virtual bool Init(const net::IPEndPoint& local_address, | 37 virtual bool Init(const net::IPEndPoint& local_address, |
38 const net::IPEndPoint& remote_address) OVERRIDE; | 38 const net::IPEndPoint& remote_address) OVERRIDE; |
39 virtual void Send(const net::IPEndPoint& to, | 39 virtual void Send(const net::IPEndPoint& to, |
40 const std::vector<char>& data) OVERRIDE; | 40 const std::vector<char>& data) OVERRIDE; |
(...skipping 30 matching lines...) Expand all Loading... |
71 | 71 |
72 scoped_ptr<net::StreamSocket> socket_; | 72 scoped_ptr<net::StreamSocket> socket_; |
73 scoped_refptr<net::GrowableIOBuffer> read_buffer_; | 73 scoped_refptr<net::GrowableIOBuffer> read_buffer_; |
74 std::queue<scoped_refptr<net::DrainableIOBuffer> > write_queue_; | 74 std::queue<scoped_refptr<net::DrainableIOBuffer> > write_queue_; |
75 scoped_refptr<net::DrainableIOBuffer> write_buffer_; | 75 scoped_refptr<net::DrainableIOBuffer> write_buffer_; |
76 | 76 |
77 bool write_pending_; | 77 bool write_pending_; |
78 | 78 |
79 bool connected_; | 79 bool connected_; |
80 | 80 |
| 81 P2PSocketType type_; |
| 82 |
81 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostTcpBase); | 83 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostTcpBase); |
82 }; | 84 }; |
83 | 85 |
84 class CONTENT_EXPORT P2PSocketHostTcp : public P2PSocketHostTcpBase { | 86 class CONTENT_EXPORT P2PSocketHostTcp : public P2PSocketHostTcpBase { |
85 public: | 87 public: |
86 P2PSocketHostTcp(IPC::Sender* message_sender, int id); | 88 P2PSocketHostTcp(IPC::Sender* message_sender, int id, P2PSocketType type); |
87 virtual ~P2PSocketHostTcp(); | 89 virtual ~P2PSocketHostTcp(); |
88 | 90 |
89 protected: | 91 protected: |
90 virtual int ProcessInput(char* input, int input_len) OVERRIDE; | 92 virtual int ProcessInput(char* input, int input_len) OVERRIDE; |
91 virtual void DoSend(const net::IPEndPoint& to, | 93 virtual void DoSend(const net::IPEndPoint& to, |
92 const std::vector<char>& data) OVERRIDE; | 94 const std::vector<char>& data) OVERRIDE; |
93 private: | 95 private: |
94 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostTcp); | 96 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostTcp); |
95 }; | 97 }; |
96 | 98 |
97 // P2PSocketHostStunTcp class provides the framing of STUN messages when used | 99 // P2PSocketHostStunTcp class provides the framing of STUN messages when used |
98 // with TURN. These messages will not have length at front of the packet and | 100 // with TURN. These messages will not have length at front of the packet and |
99 // are padded to multiple of 4 bytes. | 101 // are padded to multiple of 4 bytes. |
100 // Formatting of messages is defined in RFC5766. | 102 // Formatting of messages is defined in RFC5766. |
101 class CONTENT_EXPORT P2PSocketHostStunTcp : public P2PSocketHostTcpBase { | 103 class CONTENT_EXPORT P2PSocketHostStunTcp : public P2PSocketHostTcpBase { |
102 public: | 104 public: |
103 P2PSocketHostStunTcp(IPC::Sender* message_sender, int id); | 105 P2PSocketHostStunTcp(IPC::Sender* message_sender, int id, P2PSocketType type); |
104 virtual ~P2PSocketHostStunTcp(); | 106 virtual ~P2PSocketHostStunTcp(); |
105 | 107 |
106 protected: | 108 protected: |
107 virtual int ProcessInput(char* input, int input_len) OVERRIDE; | 109 virtual int ProcessInput(char* input, int input_len) OVERRIDE; |
108 virtual void DoSend(const net::IPEndPoint& to, | 110 virtual void DoSend(const net::IPEndPoint& to, |
109 const std::vector<char>& data) OVERRIDE; | 111 const std::vector<char>& data) OVERRIDE; |
110 private: | 112 private: |
111 int GetExpectedPacketSize(const char* data, int len, int* pad_bytes); | 113 int GetExpectedPacketSize(const char* data, int len, int* pad_bytes); |
112 | 114 |
113 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostStunTcp); | 115 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostStunTcp); |
114 }; | 116 }; |
115 | 117 |
116 | 118 |
117 } // namespace content | 119 } // namespace content |
118 | 120 |
119 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TCP_H_ | 121 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TCP_H_ |
OLD | NEW |