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_UDP_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_UDP_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_UDP_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_UDP_H_ |
7 | 7 |
8 #include "content/common/p2p_sockets.h" | 8 #include <map> |
Alpha Left Google
2011/04/09 00:44:32
#include <set> ?
Sergey Ulanov
2011/04/09 00:52:36
Done.
| |
9 | 9 |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "content/browser/renderer_host/p2p_socket_host.h" | 11 #include "content/browser/renderer_host/p2p_socket_host.h" |
12 #include "content/common/p2p_sockets.h" | |
13 #include "net/base/ip_endpoint.h" | |
12 #include "net/udp/udp_server_socket.h" | 14 #include "net/udp/udp_server_socket.h" |
13 | 15 |
14 class P2PSocketHostUdp : public P2PSocketHost { | 16 class P2PSocketHostUdp : public P2PSocketHost { |
15 public: | 17 public: |
16 P2PSocketHostUdp(P2PSocketsHost* host, int routing_id, int id); | 18 P2PSocketHostUdp(IPC::Message::Sender* message_sender, |
19 int routing_id, int id); | |
Alpha Left Google
2011/04/09 00:44:32
nit: indentation.
Sergey Ulanov
2011/04/09 00:52:36
Looks correct to me
| |
17 virtual ~P2PSocketHostUdp(); | 20 virtual ~P2PSocketHostUdp(); |
18 | 21 |
19 // P2PSocketHost overrides. | 22 // P2PSocketHost overrides. |
20 virtual bool Init(const net::IPEndPoint& local_address) OVERRIDE; | 23 virtual bool Init(const net::IPEndPoint& local_address) OVERRIDE; |
21 virtual void Send(const net::IPEndPoint& socket_address, | 24 virtual void Send(const net::IPEndPoint& to, |
22 const std::vector<char>& data) OVERRIDE; | 25 const std::vector<char>& data) OVERRIDE; |
23 | 26 |
24 private: | 27 private: |
28 friend class P2PSocketHostUdpTest; | |
29 | |
25 enum State { | 30 enum State { |
26 STATE_UNINITIALIZED, | 31 STATE_UNINITIALIZED, |
27 STATE_OPEN, | 32 STATE_OPEN, |
28 STATE_ERROR, | 33 STATE_ERROR, |
29 }; | 34 }; |
30 | 35 |
36 typedef std::set<net::IPEndPoint> AuthorizedPeerSet; | |
37 | |
31 void OnError(); | 38 void OnError(); |
32 void DoRead(); | 39 void DoRead(); |
33 void DidCompleteRead(int result); | 40 void DidCompleteRead(int result); |
34 | 41 |
35 // Callbacks for RecvFrom() and SendTo(). | 42 // Callbacks for RecvFrom() and SendTo(). |
36 void OnRecv(int result); | 43 void OnRecv(int result); |
37 void OnSend(int result); | 44 void OnSend(int result); |
38 | 45 |
39 State state_; | 46 State state_; |
40 scoped_ptr<net::DatagramServerSocket> socket_; | 47 scoped_ptr<net::DatagramServerSocket> socket_; |
41 scoped_refptr<net::IOBuffer> recv_buffer_; | 48 scoped_refptr<net::IOBuffer> recv_buffer_; |
42 net::IPEndPoint recv_address_; | 49 net::IPEndPoint recv_address_; |
43 bool send_pending_; | 50 bool send_pending_; |
44 | 51 |
52 // Set of peer for which we have received STUN binding request or | |
53 // response. | |
54 AuthorizedPeerSet authorized_peers_; | |
55 | |
45 net::CompletionCallbackImpl<P2PSocketHostUdp> recv_callback_; | 56 net::CompletionCallbackImpl<P2PSocketHostUdp> recv_callback_; |
46 net::CompletionCallbackImpl<P2PSocketHostUdp> send_callback_; | 57 net::CompletionCallbackImpl<P2PSocketHostUdp> send_callback_; |
47 | 58 |
48 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostUdp); | 59 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostUdp); |
49 }; | 60 }; |
50 | 61 |
51 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_UDP_H_ | 62 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_UDP_H_ |
OLD | NEW |