1 // Copyright (c) 2012 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_RENDERER_P2P_PORT_ALLOCATOR_H_
6 #define CONTENT_RENDERER_P2P_PORT_ALLOCATOR_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "net/base/net_util.h"
11 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h"
12 #include "third_party/libjingle/source/talk/p2p/client/basicportallocator.h"
21 class P2PHostAddressRequest
;
22 class P2PPortAllocatorSession
;
23 class P2PSocketDispatcher
;
25 // TODO(sergeyu): There is overlap between this class and HttpPortAllocator.
26 // Refactor this class to inherit from HttpPortAllocator to avoid code
28 class P2PPortAllocator
: public cricket::BasicPortAllocator
{
34 struct RelayServerConfig
{
40 std::string server_address
;
42 std::string transport_type
;
46 std::set
<rtc::SocketAddress
> stun_servers
;
48 std::vector
<RelayServerConfig
> relays
;
51 // Disable TCP-based transport when set to true.
52 bool disable_tcp_transport
;
55 P2PPortAllocator(blink::WebFrame
* web_frame
,
56 P2PSocketDispatcher
* socket_dispatcher
,
57 rtc::NetworkManager
* network_manager
,
58 rtc::PacketSocketFactory
* socket_factory
,
59 const Config
& config
);
60 virtual ~P2PPortAllocator();
62 virtual cricket::PortAllocatorSession
* CreateSessionInternal(
63 const std::string
& content_name
,
65 const std::string
& ice_username_fragment
,
66 const std::string
& ice_password
) OVERRIDE
;
69 friend class P2PPortAllocatorSession
;
71 blink::WebFrame
* web_frame_
;
72 P2PSocketDispatcher
* socket_dispatcher_
;
75 DISALLOW_COPY_AND_ASSIGN(P2PPortAllocator
);
78 class P2PPortAllocatorSession
: public cricket::BasicPortAllocatorSession
,
79 public blink::WebURLLoaderClient
{
81 P2PPortAllocatorSession(
82 P2PPortAllocator
* allocator
,
83 const std::string
& content_name
,
85 const std::string
& ice_username_fragment
,
86 const std::string
& ice_password
);
87 virtual ~P2PPortAllocatorSession();
89 // blink::WebURLLoaderClient overrides.
90 virtual void didReceiveData(blink::WebURLLoader
* loader
,
93 int encoded_data_length
) OVERRIDE
;
94 virtual void didFinishLoading(blink::WebURLLoader
* loader
,
96 int64_t total_encoded_data_length
) OVERRIDE
;
97 virtual void didFail(blink::WebURLLoader
* loader
,
98 const blink::WebURLError
& error
) OVERRIDE
;
101 // Overrides for cricket::BasicPortAllocatorSession.
102 virtual void GetPortConfigurations() OVERRIDE
;
105 // This method allocates non-TURN relay sessions.
106 void AllocateLegacyRelaySession();
107 void ParseRelayResponse();
111 P2PPortAllocator
* allocator_
;
113 scoped_ptr
<blink::WebURLLoader
> relay_session_request_
;
114 int relay_session_attempts_
;
115 std::string relay_session_response_
;
116 rtc::SocketAddress relay_ip_
;
119 int relay_ssltcp_port_
;
120 int pending_relay_requests_
;
122 DISALLOW_COPY_AND_ASSIGN(P2PPortAllocatorSession
);
125 } // namespace content
127 #endif // CONTENT_RENDERER_P2P_PORT_ALLOCATOR_H_