| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "remoting/protocol/chromium_port_allocator.h" | 5 #include "remoting/protocol/chromium_port_allocator.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "net/http/http_status_code.h" | 10 #include "net/http/http_status_code.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 class ChromiumPortAllocatorSession | 23 class ChromiumPortAllocatorSession |
| 24 : public cricket::HttpPortAllocatorSessionBase, | 24 : public cricket::HttpPortAllocatorSessionBase, |
| 25 public net::URLFetcherDelegate { | 25 public net::URLFetcherDelegate { |
| 26 public: | 26 public: |
| 27 ChromiumPortAllocatorSession( | 27 ChromiumPortAllocatorSession( |
| 28 cricket::HttpPortAllocatorBase* allocator, | 28 cricket::HttpPortAllocatorBase* allocator, |
| 29 const std::string& content_name, | 29 const std::string& content_name, |
| 30 int component, | 30 int component, |
| 31 const std::string& ice_username_fragment, | 31 const std::string& ice_username_fragment, |
| 32 const std::string& ice_password, | 32 const std::string& ice_password, |
| 33 const std::vector<talk_base::SocketAddress>& stun_hosts, | 33 const std::vector<rtc::SocketAddress>& stun_hosts, |
| 34 const std::vector<std::string>& relay_hosts, | 34 const std::vector<std::string>& relay_hosts, |
| 35 const std::string& relay, | 35 const std::string& relay, |
| 36 const scoped_refptr<net::URLRequestContextGetter>& url_context); | 36 const scoped_refptr<net::URLRequestContextGetter>& url_context); |
| 37 virtual ~ChromiumPortAllocatorSession(); | 37 virtual ~ChromiumPortAllocatorSession(); |
| 38 | 38 |
| 39 // cricket::HttpPortAllocatorBase overrides. | 39 // cricket::HttpPortAllocatorBase overrides. |
| 40 virtual void ConfigReady(cricket::PortConfiguration* config) OVERRIDE; | 40 virtual void ConfigReady(cricket::PortConfiguration* config) OVERRIDE; |
| 41 virtual void SendSessionRequest(const std::string& host, int port) OVERRIDE; | 41 virtual void SendSessionRequest(const std::string& host, int port) OVERRIDE; |
| 42 | 42 |
| 43 // net::URLFetcherDelegate interface. | 43 // net::URLFetcherDelegate interface. |
| 44 virtual void OnURLFetchComplete(const net::URLFetcher* url_fetcher) OVERRIDE; | 44 virtual void OnURLFetchComplete(const net::URLFetcher* url_fetcher) OVERRIDE; |
| 45 | 45 |
| 46 private: | 46 private: |
| 47 scoped_refptr<net::URLRequestContextGetter> url_context_; | 47 scoped_refptr<net::URLRequestContextGetter> url_context_; |
| 48 std::set<const net::URLFetcher*> url_fetchers_; | 48 std::set<const net::URLFetcher*> url_fetchers_; |
| 49 | 49 |
| 50 DISALLOW_COPY_AND_ASSIGN(ChromiumPortAllocatorSession); | 50 DISALLOW_COPY_AND_ASSIGN(ChromiumPortAllocatorSession); |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 ChromiumPortAllocatorSession::ChromiumPortAllocatorSession( | 53 ChromiumPortAllocatorSession::ChromiumPortAllocatorSession( |
| 54 cricket::HttpPortAllocatorBase* allocator, | 54 cricket::HttpPortAllocatorBase* allocator, |
| 55 const std::string& content_name, | 55 const std::string& content_name, |
| 56 int component, | 56 int component, |
| 57 const std::string& ice_username_fragment, | 57 const std::string& ice_username_fragment, |
| 58 const std::string& ice_password, | 58 const std::string& ice_password, |
| 59 const std::vector<talk_base::SocketAddress>& stun_hosts, | 59 const std::vector<rtc::SocketAddress>& stun_hosts, |
| 60 const std::vector<std::string>& relay_hosts, | 60 const std::vector<std::string>& relay_hosts, |
| 61 const std::string& relay, | 61 const std::string& relay, |
| 62 const scoped_refptr<net::URLRequestContextGetter>& url_context) | 62 const scoped_refptr<net::URLRequestContextGetter>& url_context) |
| 63 : HttpPortAllocatorSessionBase(allocator, | 63 : HttpPortAllocatorSessionBase(allocator, |
| 64 content_name, | 64 content_name, |
| 65 component, | 65 component, |
| 66 ice_username_fragment, | 66 ice_username_fragment, |
| 67 ice_password, | 67 ice_password, |
| 68 stun_hosts, | 68 stun_hosts, |
| 69 relay_hosts, | 69 relay_hosts, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 126 |
| 127 ReceiveSessionResponse(response); | 127 ReceiveSessionResponse(response); |
| 128 } | 128 } |
| 129 | 129 |
| 130 } // namespace | 130 } // namespace |
| 131 | 131 |
| 132 // static | 132 // static |
| 133 scoped_ptr<ChromiumPortAllocator> ChromiumPortAllocator::Create( | 133 scoped_ptr<ChromiumPortAllocator> ChromiumPortAllocator::Create( |
| 134 const scoped_refptr<net::URLRequestContextGetter>& url_context, | 134 const scoped_refptr<net::URLRequestContextGetter>& url_context, |
| 135 const NetworkSettings& network_settings) { | 135 const NetworkSettings& network_settings) { |
| 136 scoped_ptr<talk_base::NetworkManager> network_manager( | 136 scoped_ptr<rtc::NetworkManager> network_manager( |
| 137 new talk_base::BasicNetworkManager()); | 137 new rtc::BasicNetworkManager()); |
| 138 scoped_ptr<talk_base::PacketSocketFactory> socket_factory( | 138 scoped_ptr<rtc::PacketSocketFactory> socket_factory( |
| 139 new ChromiumPacketSocketFactory()); | 139 new ChromiumPacketSocketFactory()); |
| 140 scoped_ptr<ChromiumPortAllocator> result( | 140 scoped_ptr<ChromiumPortAllocator> result( |
| 141 new ChromiumPortAllocator(url_context, network_manager.Pass(), | 141 new ChromiumPortAllocator(url_context, network_manager.Pass(), |
| 142 socket_factory.Pass())); | 142 socket_factory.Pass())); |
| 143 | 143 |
| 144 // We always use PseudoTcp to provide a reliable channel. It provides poor | 144 // We always use PseudoTcp to provide a reliable channel. It provides poor |
| 145 // performance when combined with TCP-based transport, so we have to disable | 145 // performance when combined with TCP-based transport, so we have to disable |
| 146 // TCP ports. ENABLE_SHARED_UFRAG flag is specified so that the same username | 146 // TCP ports. ENABLE_SHARED_UFRAG flag is specified so that the same username |
| 147 // fragment is shared between all candidates for this channel. | 147 // fragment is shared between all candidates for this channel. |
| 148 int flags = cricket::PORTALLOCATOR_DISABLE_TCP | | 148 int flags = cricket::PORTALLOCATOR_DISABLE_TCP | |
| 149 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | | 149 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | |
| 150 cricket::PORTALLOCATOR_ENABLE_IPV6; | 150 cricket::PORTALLOCATOR_ENABLE_IPV6; |
| 151 | 151 |
| 152 if (!(network_settings.flags & NetworkSettings::NAT_TRAVERSAL_STUN)) | 152 if (!(network_settings.flags & NetworkSettings::NAT_TRAVERSAL_STUN)) |
| 153 flags |= cricket::PORTALLOCATOR_DISABLE_STUN; | 153 flags |= cricket::PORTALLOCATOR_DISABLE_STUN; |
| 154 | 154 |
| 155 if (!(network_settings.flags & NetworkSettings::NAT_TRAVERSAL_RELAY)) | 155 if (!(network_settings.flags & NetworkSettings::NAT_TRAVERSAL_RELAY)) |
| 156 flags |= cricket::PORTALLOCATOR_DISABLE_RELAY; | 156 flags |= cricket::PORTALLOCATOR_DISABLE_RELAY; |
| 157 | 157 |
| 158 result->set_flags(flags); | 158 result->set_flags(flags); |
| 159 result->SetPortRange(network_settings.min_port, | 159 result->SetPortRange(network_settings.min_port, |
| 160 network_settings.max_port); | 160 network_settings.max_port); |
| 161 | 161 |
| 162 return result.Pass(); | 162 return result.Pass(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 ChromiumPortAllocator::ChromiumPortAllocator( | 165 ChromiumPortAllocator::ChromiumPortAllocator( |
| 166 const scoped_refptr<net::URLRequestContextGetter>& url_context, | 166 const scoped_refptr<net::URLRequestContextGetter>& url_context, |
| 167 scoped_ptr<talk_base::NetworkManager> network_manager, | 167 scoped_ptr<rtc::NetworkManager> network_manager, |
| 168 scoped_ptr<talk_base::PacketSocketFactory> socket_factory) | 168 scoped_ptr<rtc::PacketSocketFactory> socket_factory) |
| 169 : HttpPortAllocatorBase(network_manager.get(), | 169 : HttpPortAllocatorBase(network_manager.get(), |
| 170 socket_factory.get(), | 170 socket_factory.get(), |
| 171 std::string()), | 171 std::string()), |
| 172 url_context_(url_context), | 172 url_context_(url_context), |
| 173 network_manager_(network_manager.Pass()), | 173 network_manager_(network_manager.Pass()), |
| 174 socket_factory_(socket_factory.Pass()) {} | 174 socket_factory_(socket_factory.Pass()) {} |
| 175 | 175 |
| 176 ChromiumPortAllocator::~ChromiumPortAllocator() { | 176 ChromiumPortAllocator::~ChromiumPortAllocator() { |
| 177 } | 177 } |
| 178 | 178 |
| 179 cricket::PortAllocatorSession* ChromiumPortAllocator::CreateSessionInternal( | 179 cricket::PortAllocatorSession* ChromiumPortAllocator::CreateSessionInternal( |
| 180 const std::string& content_name, | 180 const std::string& content_name, |
| 181 int component, | 181 int component, |
| 182 const std::string& ice_username_fragment, | 182 const std::string& ice_username_fragment, |
| 183 const std::string& ice_password) { | 183 const std::string& ice_password) { |
| 184 return new ChromiumPortAllocatorSession( | 184 return new ChromiumPortAllocatorSession( |
| 185 this, content_name, component, ice_username_fragment, ice_password, | 185 this, content_name, component, ice_username_fragment, ice_password, |
| 186 stun_hosts(), relay_hosts(), relay_token(), url_context_); | 186 stun_hosts(), relay_hosts(), relay_token(), url_context_); |
| 187 } | 187 } |
| 188 | 188 |
| 189 } // namespace protocol | 189 } // namespace protocol |
| 190 } // namespace remoting | 190 } // namespace remoting |
| OLD | NEW |