OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/client/plugin/pepper_port_allocator.h" | 5 #include "remoting/client/plugin/pepper_port_allocator.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "net/base/net_util.h" | 9 #include "net/base/net_util.h" |
10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 if (stun_hosts.size() > 0) { | 96 if (stun_hosts.size() > 0) { |
97 stun_address_ = stun_hosts[0]; | 97 stun_address_ = stun_hosts[0]; |
98 } | 98 } |
99 } | 99 } |
100 | 100 |
101 PepperPortAllocatorSession::~PepperPortAllocatorSession() { | 101 PepperPortAllocatorSession::~PepperPortAllocatorSession() { |
102 } | 102 } |
103 | 103 |
104 void PepperPortAllocatorSession::ConfigReady( | 104 void PepperPortAllocatorSession::ConfigReady( |
105 cricket::PortConfiguration* config) { | 105 cricket::PortConfiguration* config) { |
106 if (config->stun_address.IsUnresolved()) { | 106 if (!config->stun_servers.empty() && |
Sergey Ulanov
2014/08/08 19:57:16
FYI: there is https://codereview.chromium.org/4529
| |
107 config->stun_servers.begin()->IsUnresolved()) { | |
107 // Make sure that the address that we pass to ConfigReady() is | 108 // Make sure that the address that we pass to ConfigReady() is |
108 // always resolved. | 109 // always resolved. |
109 if (stun_address_.IsUnresolved()) { | 110 config->stun_servers.clear(); |
110 config->stun_address.Clear(); | 111 if (!stun_address_.IsUnresolved()) |
111 } else { | 112 config->stun_servers.insert(stun_address_); |
112 config->stun_address = stun_address_; | |
113 } | |
114 } | 113 } |
115 | 114 |
116 // Filter out non-UDP relay ports, so that we don't try using TCP. | 115 // Filter out non-UDP relay ports, so that we don't try using TCP. |
117 for (cricket::PortConfiguration::RelayList::iterator relay = | 116 for (cricket::PortConfiguration::RelayList::iterator relay = |
118 config->relays.begin(); relay != config->relays.end(); ++relay) { | 117 config->relays.begin(); relay != config->relays.end(); ++relay) { |
119 cricket::PortList filtered_ports; | 118 cricket::PortList filtered_ports; |
120 for (cricket::PortList::iterator port = | 119 for (cricket::PortList::iterator port = |
121 relay->ports.begin(); port != relay->ports.end(); ++port) { | 120 relay->ports.begin(); port != relay->ports.end(); ++port) { |
122 if (port->proto == cricket::PROTO_UDP) { | 121 if (port->proto == cricket::PROTO_UDP) { |
123 filtered_ports.push_back(*port); | 122 filtered_ports.push_back(*port); |
124 } | 123 } |
125 } | 124 } |
126 relay->ports = filtered_ports; | 125 relay->ports = filtered_ports; |
127 } | 126 } |
128 cricket::BasicPortAllocatorSession::ConfigReady(config); | 127 cricket::BasicPortAllocatorSession::ConfigReady(config); |
129 } | 128 } |
130 | 129 |
131 void PepperPortAllocatorSession::GetPortConfigurations() { | 130 void PepperPortAllocatorSession::GetPortConfigurations() { |
132 // Add an empty configuration synchronously, so a local connection | 131 // Add an empty configuration synchronously, so a local connection |
133 // can be started immediately. | 132 // can be started immediately. |
134 ConfigReady(new cricket::PortConfiguration( | 133 ConfigReady(new cricket::PortConfiguration( |
135 rtc::SocketAddress(), std::string(), std::string())); | 134 cricket::ServerAddresses(), std::string(), std::string())); |
136 | 135 |
137 ResolveStunServerAddress(); | 136 ResolveStunServerAddress(); |
138 TryCreateRelaySession(); | 137 TryCreateRelaySession(); |
139 } | 138 } |
140 | 139 |
141 void PepperPortAllocatorSession::ResolveStunServerAddress() { | 140 void PepperPortAllocatorSession::ResolveStunServerAddress() { |
142 if (stun_address_.IsNil()) { | 141 if (stun_address_.IsNil()) { |
143 return; | 142 return; |
144 } | 143 } |
145 | 144 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 // and Relay parameters are stored together in PortConfiguration | 190 // and Relay parameters are stored together in PortConfiguration |
192 // and ReceiveSessionResponse() doesn't save relay session | 191 // and ReceiveSessionResponse() doesn't save relay session |
193 // configuration for the case we resolve STUN address later. This | 192 // configuration for the case we resolve STUN address later. This |
194 // method invokes overriden ConfigReady() which then submits | 193 // method invokes overriden ConfigReady() which then submits |
195 // resolved |stun_address_|. | 194 // resolved |stun_address_|. |
196 // | 195 // |
197 // TODO(sergeyu): Refactor HttpPortAllocatorSessionBase to fix this. | 196 // TODO(sergeyu): Refactor HttpPortAllocatorSessionBase to fix this. |
198 ReceiveSessionResponse(std::string(relay_response_body_.begin(), | 197 ReceiveSessionResponse(std::string(relay_response_body_.begin(), |
199 relay_response_body_.end())); | 198 relay_response_body_.end())); |
200 } else { | 199 } else { |
200 cricket::ServerAddresses stun; | |
201 stun.insert(stun_address_); | |
201 ConfigReady(new cricket::PortConfiguration( | 202 ConfigReady(new cricket::PortConfiguration( |
202 stun_address_, std::string(), std::string())); | 203 stun, std::string(), std::string())); |
203 } | 204 } |
204 } | 205 } |
205 | 206 |
206 void PepperPortAllocatorSession::SendSessionRequest( | 207 void PepperPortAllocatorSession::SendSessionRequest( |
207 const std::string& host, | 208 const std::string& host, |
208 int port) { | 209 int port) { |
209 relay_url_loader_.reset(new pp::URLLoader(instance_)); | 210 relay_url_loader_.reset(new pp::URLLoader(instance_)); |
210 pp::URLRequestInfo request_info(instance_); | 211 pp::URLRequestInfo request_info(instance_); |
211 std::string url = "https://" + host + ":" + base::IntToString(port) + | 212 std::string url = "https://" + host + ":" + base::IntToString(port) + |
212 GetSessionRequestUrl() + "&sn=1"; | 213 GetSessionRequestUrl() + "&sn=1"; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
328 const std::string& content_name, | 329 const std::string& content_name, |
329 int component, | 330 int component, |
330 const std::string& ice_username_fragment, | 331 const std::string& ice_username_fragment, |
331 const std::string& ice_password) { | 332 const std::string& ice_password) { |
332 return new PepperPortAllocatorSession( | 333 return new PepperPortAllocatorSession( |
333 this, content_name, component, ice_username_fragment, ice_password, | 334 this, content_name, component, ice_username_fragment, ice_password, |
334 stun_hosts(), relay_hosts(), relay_token(), instance_); | 335 stun_hosts(), relay_hosts(), relay_token(), instance_); |
335 } | 336 } |
336 | 337 |
337 } // namespace remoting | 338 } // namespace remoting |
OLD | NEW |