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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_UDP_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_UDP_H_
12 #include "base/compiler_specific.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop/message_loop.h"
16 #include "content/browser/renderer_host/p2p/socket_host.h"
17 #include "content/common/content_export.h"
18 #include "content/common/p2p_sockets.h"
19 #include "net/base/ip_endpoint.h"
20 #include "net/udp/udp_server_socket.h"
24 class P2PMessageThrottler;
26 class CONTENT_EXPORT P2PSocketHostUdp : public P2PSocketHost {
28 P2PSocketHostUdp(IPC::Sender* message_sender, int id,
29 P2PMessageThrottler* throttler);
30 virtual ~P2PSocketHostUdp();
32 // P2PSocketHost overrides.
33 virtual bool Init(const net::IPEndPoint& local_address,
34 const net::IPEndPoint& remote_address) OVERRIDE;
35 virtual void Send(const net::IPEndPoint& to,
36 const std::vector<char>& data,
37 net::DiffServCodePoint dscp,
38 uint64 packet_id) OVERRIDE;
39 virtual P2PSocketHost* AcceptIncomingTcpConnection(
40 const net::IPEndPoint& remote_address, int id) OVERRIDE;
43 friend class P2PSocketHostUdpTest;
45 typedef std::set<net::IPEndPoint> ConnectedPeerSet;
47 struct PendingPacket {
48 PendingPacket(const net::IPEndPoint& to,
49 const std::vector<char>& content,
50 net::DiffServCodePoint dscp,
54 scoped_refptr<net::IOBuffer> data;
56 net::DiffServCodePoint dscp;
63 void OnRecv(int result);
64 void HandleReadResult(int result);
66 void DoSend(const PendingPacket& packet);
67 void OnSend(uint64 packet_id, int result);
68 void HandleSendResult(uint64 packet_id, int result);
70 scoped_ptr<net::DatagramServerSocket> socket_;
71 scoped_refptr<net::IOBuffer> recv_buffer_;
72 net::IPEndPoint recv_address_;
74 std::deque<PendingPacket> send_queue_;
76 net::DiffServCodePoint last_dscp_;
78 // Set of peer for which we have received STUN binding request or
79 // response or relay allocation request or response.
80 ConnectedPeerSet connected_peers_;
81 P2PMessageThrottler* throttler_;
83 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostUdp);
86 } // namespace content
88 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_UDP_H_