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 SsltcpHelper; | |
29 | |
28 class CONTENT_EXPORT P2PSocketHostTcpBase : public P2PSocketHost { | 30 class CONTENT_EXPORT P2PSocketHostTcpBase : public P2PSocketHost { |
29 public: | 31 public: |
30 P2PSocketHostTcpBase(IPC::Sender* message_sender, int id); | 32 P2PSocketHostTcpBase(IPC::Sender* message_sender, int id, bool ssl); |
Sergey Ulanov
2013/06/18 20:01:26
can you please define some enum (e.g. SslMode) wit
Ronghua Wu (Left Chromium)
2013/06/18 22:19:48
Reused P2PSocketType.
| |
31 virtual ~P2PSocketHostTcpBase(); | 33 virtual ~P2PSocketHostTcpBase(); |
32 | 34 |
33 bool InitAccepted(const net::IPEndPoint& remote_address, | 35 bool InitAccepted(const net::IPEndPoint& remote_address, |
34 net::StreamSocket* socket); | 36 net::StreamSocket* socket); |
35 | 37 |
36 // P2PSocketHost overrides. | 38 // P2PSocketHost overrides. |
37 virtual bool Init(const net::IPEndPoint& local_address, | 39 virtual bool Init(const net::IPEndPoint& local_address, |
38 const net::IPEndPoint& remote_address) OVERRIDE; | 40 const net::IPEndPoint& remote_address) OVERRIDE; |
39 virtual void Send(const net::IPEndPoint& to, | 41 virtual void Send(const net::IPEndPoint& to, |
40 const std::vector<char>& data) OVERRIDE; | 42 const std::vector<char>& data) OVERRIDE; |
41 virtual P2PSocketHost* AcceptIncomingTcpConnection( | 43 virtual P2PSocketHost* AcceptIncomingTcpConnection( |
42 const net::IPEndPoint& remote_address, int id) OVERRIDE; | 44 const net::IPEndPoint& remote_address, int id) OVERRIDE; |
43 | 45 |
44 protected: | 46 protected: |
45 // Derived classes will provide the implementation. | 47 // Derived classes will provide the implementation. |
46 virtual int ProcessInput(char* input, int input_len) = 0; | 48 virtual int ProcessInput(char* input, int input_len) = 0; |
47 virtual void DoSend(const net::IPEndPoint& to, | 49 virtual void DoSend(const net::IPEndPoint& to, |
48 const std::vector<char>& data) = 0; | 50 const std::vector<char>& data) = 0; |
49 | 51 |
50 void WriteOrQueue(scoped_refptr<net::DrainableIOBuffer>& buffer); | 52 void WriteOrQueue(scoped_refptr<net::DrainableIOBuffer>& buffer); |
51 void OnPacket(const std::vector<char>& data); | 53 void OnPacket(const std::vector<char>& data); |
52 void OnError(); | 54 void OnError(); |
53 | 55 |
56 int MaybeHandleSslHello(char** cur, int* cur_len, int* consumed); | |
57 | |
58 scoped_ptr<SsltcpHelper> ssltcp_helper_; | |
Sergey Ulanov
2013/06/18 20:01:26
does this need to be protected? I think P2PSocketH
| |
59 | |
60 net::IPEndPoint remote_address_; | |
Sergey Ulanov
2013/06/18 20:01:26
This still can private.
| |
61 | |
54 private: | 62 private: |
55 friend class P2PSocketHostTcpTest; | 63 friend class P2PSocketHostTcpTest; |
56 friend class P2PSocketHostTcpServerTest; | 64 friend class P2PSocketHostTcpServerTest; |
57 friend class P2PSocketHostStunTcpTest; | 65 friend class P2PSocketHostStunTcpTest; |
58 | 66 |
59 void DidCompleteRead(int result); | 67 void DidCompleteRead(int result); |
60 void DoRead(); | 68 void DoRead(); |
61 | 69 |
62 void DoWrite(); | 70 void DoWrite(); |
63 void HandleWriteResult(int result); | 71 void HandleWriteResult(int result); |
64 | 72 |
65 // Callbacks for Connect(), Read() and Write(). | 73 // Callbacks for Connect(), Read() and Write(). |
66 void OnConnected(int result); | 74 void OnConnected(int result); |
67 void OnRead(int result); | 75 void OnRead(int result); |
68 void OnWritten(int result); | 76 void OnWritten(int result); |
69 | 77 |
70 net::IPEndPoint remote_address_; | |
71 | |
72 scoped_ptr<net::StreamSocket> socket_; | 78 scoped_ptr<net::StreamSocket> socket_; |
73 scoped_refptr<net::GrowableIOBuffer> read_buffer_; | 79 scoped_refptr<net::GrowableIOBuffer> read_buffer_; |
74 std::queue<scoped_refptr<net::DrainableIOBuffer> > write_queue_; | 80 std::queue<scoped_refptr<net::DrainableIOBuffer> > write_queue_; |
75 scoped_refptr<net::DrainableIOBuffer> write_buffer_; | 81 scoped_refptr<net::DrainableIOBuffer> write_buffer_; |
76 | 82 |
77 bool write_pending_; | 83 bool write_pending_; |
78 | 84 |
79 bool connected_; | 85 bool connected_; |
80 | 86 |
81 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostTcpBase); | 87 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostTcpBase); |
82 }; | 88 }; |
83 | 89 |
84 class CONTENT_EXPORT P2PSocketHostTcp : public P2PSocketHostTcpBase { | 90 class CONTENT_EXPORT P2PSocketHostTcp : public P2PSocketHostTcpBase { |
85 public: | 91 public: |
86 P2PSocketHostTcp(IPC::Sender* message_sender, int id); | 92 P2PSocketHostTcp(IPC::Sender* message_sender, int id, bool ssl); |
87 virtual ~P2PSocketHostTcp(); | 93 virtual ~P2PSocketHostTcp(); |
88 | 94 |
89 protected: | 95 protected: |
90 virtual int ProcessInput(char* input, int input_len) OVERRIDE; | 96 virtual int ProcessInput(char* input, int input_len) OVERRIDE; |
91 virtual void DoSend(const net::IPEndPoint& to, | 97 virtual void DoSend(const net::IPEndPoint& to, |
92 const std::vector<char>& data) OVERRIDE; | 98 const std::vector<char>& data) OVERRIDE; |
93 private: | 99 private: |
94 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostTcp); | 100 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostTcp); |
95 }; | 101 }; |
96 | 102 |
97 // P2PSocketHostStunTcp class provides the framing of STUN messages when used | 103 // 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 | 104 // with TURN. These messages will not have length at front of the packet and |
99 // are padded to multiple of 4 bytes. | 105 // are padded to multiple of 4 bytes. |
100 // Formatting of messages is defined in RFC5766. | 106 // Formatting of messages is defined in RFC5766. |
101 class CONTENT_EXPORT P2PSocketHostStunTcp : public P2PSocketHostTcpBase { | 107 class CONTENT_EXPORT P2PSocketHostStunTcp : public P2PSocketHostTcpBase { |
102 public: | 108 public: |
103 P2PSocketHostStunTcp(IPC::Sender* message_sender, int id); | 109 P2PSocketHostStunTcp(IPC::Sender* message_sender, int id, bool ssl); |
104 virtual ~P2PSocketHostStunTcp(); | 110 virtual ~P2PSocketHostStunTcp(); |
105 | 111 |
106 protected: | 112 protected: |
107 virtual int ProcessInput(char* input, int input_len) OVERRIDE; | 113 virtual int ProcessInput(char* input, int input_len) OVERRIDE; |
108 virtual void DoSend(const net::IPEndPoint& to, | 114 virtual void DoSend(const net::IPEndPoint& to, |
109 const std::vector<char>& data) OVERRIDE; | 115 const std::vector<char>& data) OVERRIDE; |
110 private: | 116 private: |
111 int GetExpectedPacketSize(const char* data, int len, int* pad_bytes); | 117 int GetExpectedPacketSize(const char* data, int len, int* pad_bytes); |
112 | 118 |
113 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostStunTcp); | 119 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostStunTcp); |
114 }; | 120 }; |
115 | 121 |
116 | 122 |
117 } // namespace content | 123 } // namespace content |
118 | 124 |
119 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TCP_H_ | 125 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TCP_H_ |
OLD | NEW |