Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(492)

Side by Side Diff: remoting/protocol/port_allocator.cc

Issue 1694613002: Add IceConfig and IceConfigRequest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@url_request
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/protocol/port_allocator.h ('k') | remoting/protocol/transport_context.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/port_allocator.h" 5 #include "remoting/protocol/port_allocator.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 content_name, 89 content_name,
90 component, 90 component,
91 ice_ufrag, 91 ice_ufrag,
92 ice_pwd), 92 ice_pwd),
93 transport_context_(allocator->transport_context()), 93 transport_context_(allocator->transport_context()),
94 weak_factory_(this) {} 94 weak_factory_(this) {}
95 95
96 PortAllocatorSession::~PortAllocatorSession() {} 96 PortAllocatorSession::~PortAllocatorSession() {}
97 97
98 void PortAllocatorSession::GetPortConfigurations() { 98 void PortAllocatorSession::GetPortConfigurations() {
99 transport_context_->GetJingleInfo(base::Bind( 99 transport_context_->GetIceConfig(base::Bind(
100 &PortAllocatorSession::OnJingleInfo, weak_factory_.GetWeakPtr())); 100 &PortAllocatorSession::OnIceConfig, weak_factory_.GetWeakPtr()));
101 } 101 }
102 102
103 void PortAllocatorSession::OnJingleInfo( 103 void PortAllocatorSession::OnIceConfig(const IceConfig& ice_config) {
104 std::vector<rtc::SocketAddress> stun_hosts, 104 ice_config_ = ice_config;
105 std::vector<std::string> relay_hosts,
106 std::string relay_token) {
107 stun_hosts_ = stun_hosts;
108 relay_hosts_ = relay_hosts;
109 relay_token_ = relay_token;
110 105
111 // Creating relay sessions can take time and is done asynchronously. 106 // Creating relay sessions can take time and is done asynchronously.
112 // Creating stun sessions could also take time and could be done aysnc also, 107 // Creating stun sessions could also take time and could be done aysnc also,
113 // but for now is done here and added to the initial config. Note any later 108 // but for now is done here and added to the initial config. Note any later
114 // configs will have unresolved stun ips and will be discarded by the 109 // configs will have unresolved stun ips and will be discarded by the
115 // AllocationSequence. 110 // AllocationSequence.
116 cricket::ServerAddresses hosts; 111 cricket::ServerAddresses stun_servers;
117 for (const auto& host : stun_hosts_) { 112 for (const auto& host : ice_config_.stun_servers) {
118 hosts.insert(host); 113 stun_servers.insert(host);
119 } 114 }
120 115
121 cricket::PortConfiguration* config = 116 cricket::PortConfiguration* config =
122 new cricket::PortConfiguration(hosts, username(), password()); 117 new cricket::PortConfiguration(stun_servers, username(), password());
123 ConfigReady(config); 118 ConfigReady(config);
124 TryCreateRelaySession(); 119 TryCreateRelaySession();
125 } 120 }
126 121
127 void PortAllocatorSession::TryCreateRelaySession() { 122 void PortAllocatorSession::TryCreateRelaySession() {
128 if (flags() & cricket::PORTALLOCATOR_DISABLE_RELAY) 123 if (flags() & cricket::PORTALLOCATOR_DISABLE_RELAY)
129 return; 124 return;
130 125
131 if (attempts_ == kNumRetries) { 126 if (attempts_ == kNumRetries) {
132 LOG(ERROR) << "PortAllocator: maximum number of requests reached; " 127 LOG(ERROR) << "PortAllocator: maximum number of requests reached; "
133 << "giving up on relay."; 128 << "giving up on relay.";
134 return; 129 return;
135 } 130 }
136 131
137 if (relay_hosts_.empty()) { 132 if (ice_config_.relay_servers.empty()) {
138 LOG(ERROR) << "PortAllocator: no relay hosts configured."; 133 LOG(ERROR) << "PortAllocator: no relay servers configured.";
139 return; 134 return;
140 } 135 }
141 136
142 if (relay_token_.empty()){ 137 if (ice_config_.relay_token.empty()){
143 LOG(WARNING) << "No relay auth token found."; 138 LOG(WARNING) << "No relay auth token found.";
144 return; 139 return;
145 } 140 }
146 141
147 // Choose the next host to try. 142 // Choose the next host to try.
148 std::string host = relay_hosts_[attempts_ % relay_hosts_.size()]; 143 std::string host =
144 ice_config_.relay_servers[attempts_ % ice_config_.relay_servers.size()];
149 attempts_++; 145 attempts_++;
150 146
151 DCHECK(!username().empty()); 147 DCHECK(!username().empty());
152 DCHECK(!password().empty()); 148 DCHECK(!password().empty());
153 std::string url = "https://" + host + "/create_session?username=" + 149 std::string url = "https://" + host + "/create_session?username=" +
154 net::EscapeUrlEncodedData(username(), false) + 150 net::EscapeUrlEncodedData(username(), false) +
155 "&password=" + 151 "&password=" +
156 net::EscapeUrlEncodedData(password(), false) + "&sn=1"; 152 net::EscapeUrlEncodedData(password(), false) + "&sn=1";
157 scoped_ptr<UrlRequest> url_request = 153 scoped_ptr<UrlRequest> url_request =
158 transport_context_->url_request_factory()->CreateUrlRequest(url); 154 transport_context_->url_request_factory()->CreateUrlRequest(url);
159 url_request->AddHeader("X-Talk-Google-Relay-Auth: " + relay_token()); 155 url_request->AddHeader("X-Talk-Google-Relay-Auth: " +
160 url_request->AddHeader("X-Google-Relay-Auth: " + relay_token()); 156 ice_config_.relay_token);
157 url_request->AddHeader("X-Google-Relay-Auth: " + ice_config_.relay_token);
161 url_request->AddHeader("X-Stream-Type: chromoting"); 158 url_request->AddHeader("X-Stream-Type: chromoting");
162 url_request->Start(base::Bind(&PortAllocatorSession::OnSessionRequestResult, 159 url_request->Start(base::Bind(&PortAllocatorSession::OnSessionRequestResult,
163 base::Unretained(this))); 160 base::Unretained(this)));
164 url_requests_.insert(std::move(url_request)); 161 url_requests_.insert(std::move(url_request));
165 } 162 }
166 163
167 void PortAllocatorSession::OnSessionRequestResult( 164 void PortAllocatorSession::OnSessionRequestResult(
168 const UrlRequest::Result& result) { 165 const UrlRequest::Result& result) {
169 if (!result.success || result.status != net::HTTP_OK) { 166 if (!result.success || result.status != net::HTTP_OK) {
170 LOG(WARNING) << "Received error when allocating relay session: " 167 LOG(WARNING) << "Received error when allocating relay session: "
171 << result.status; 168 << result.status;
172 TryCreateRelaySession(); 169 TryCreateRelaySession();
173 return; 170 return;
174 } 171 }
175 172
176 StringMap map = ParseMap(result.response_body); 173 StringMap map = ParseMap(result.response_body);
177 174
178 if (!username().empty() && map["username"] != username()) { 175 if (!username().empty() && map["username"] != username()) {
179 LOG(WARNING) << "Received unexpected username value from relay server."; 176 LOG(WARNING) << "Received unexpected username value from relay server.";
180 } 177 }
181 if (!password().empty() && map["password"] != password()) { 178 if (!password().empty() && map["password"] != password()) {
182 LOG(WARNING) << "Received unexpected password value from relay server."; 179 LOG(WARNING) << "Received unexpected password value from relay server.";
183 } 180 }
184 181
185 cricket::ServerAddresses hosts; 182 cricket::ServerAddresses stun_servers;
186 for (const auto& host : stun_hosts_) { 183 for (const auto& host : ice_config_.stun_servers) {
187 hosts.insert(host); 184 stun_servers.insert(host);
188 } 185 }
189 186
190 cricket::PortConfiguration* config = 187 cricket::PortConfiguration* config = new cricket::PortConfiguration(
191 new cricket::PortConfiguration(hosts, map["username"], map["password"]); 188 stun_servers, map["username"], map["password"]);
192 189
193 std::string relay_ip = map["relay.ip"]; 190 std::string relay_ip = map["relay.ip"];
194 std::string relay_port = map["relay.udp_port"]; 191 std::string relay_port = map["relay.udp_port"];
195 unsigned relay_port_int; 192 unsigned relay_port_int;
196 193
197 if (!relay_ip.empty() && !relay_port.empty() && 194 if (!relay_ip.empty() && !relay_port.empty() &&
198 base::StringToUint(relay_port, &relay_port_int)) { 195 base::StringToUint(relay_port, &relay_port_int)) {
199 cricket::RelayServerConfig relay_config(cricket::RELAY_GTURN); 196 cricket::RelayServerConfig relay_config(cricket::RELAY_GTURN);
200 rtc::SocketAddress address(relay_ip, relay_port_int); 197 rtc::SocketAddress address(relay_ip, relay_port_int);
201 relay_config.ports.push_back( 198 relay_config.ports.push_back(
202 cricket::ProtocolAddress(address, cricket::PROTO_UDP)); 199 cricket::ProtocolAddress(address, cricket::PROTO_UDP));
203 config->AddRelay(relay_config); 200 config->AddRelay(relay_config);
204 } 201 }
205 202
206 ConfigReady(config); 203 ConfigReady(config);
207 } 204 }
208 205
209 } // namespace protocol 206 } // namespace protocol
210 } // namespace remoting 207 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/port_allocator.h ('k') | remoting/protocol/transport_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698