OLD | NEW |
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 "blimp/client/core/session/assignment_source.h" | 5 #include "blimp/client/core/session/assignment_source.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 // Must be called on a thread suitable for file IO. | 111 // Must be called on a thread suitable for file IO. |
112 Assignment GetAssignmentFromCommandLine() { | 112 Assignment GetAssignmentFromCommandLine() { |
113 Assignment assignment; | 113 Assignment assignment; |
114 | 114 |
115 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 115 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
116 assignment.client_auth_token = GetClientAuthToken(*cmd_line); | 116 assignment.client_auth_token = GetClientAuthToken(*cmd_line); |
117 CHECK(!assignment.client_auth_token.empty()) | 117 CHECK(!assignment.client_auth_token.empty()) |
118 << "No client auth token provided."; | 118 << "No client auth token provided."; |
119 | 119 |
120 unsigned port_parsed = 0; | 120 unsigned port_parsed = 0; |
121 if (!base::StringToUint( | 121 if (!base::StringToUint(cmd_line->GetSwitchValueASCII(switches::kEnginePort), |
122 cmd_line->GetSwitchValueASCII(switches::kEnginePort), | 122 &port_parsed) || |
123 &port_parsed) || !IsValidIpPortNumber(port_parsed)) { | 123 !IsValidIpPortNumber(port_parsed)) { |
124 DLOG(FATAL) << "--engine-port must be a value between 1 and 65535."; | 124 DLOG(FATAL) << "--engine-port must be a value between 1 and 65535."; |
125 return Assignment(); | 125 return Assignment(); |
126 } | 126 } |
127 | 127 |
128 net::IPAddress ip_address; | 128 net::IPAddress ip_address; |
129 std::string ip_str = cmd_line->GetSwitchValueASCII(switches::kEngineIP); | 129 std::string ip_str = cmd_line->GetSwitchValueASCII(switches::kEngineIP); |
130 if (!ip_address.AssignFromIPLiteral(ip_str)) { | 130 if (!ip_address.AssignFromIPLiteral(ip_str)) { |
131 DLOG(FATAL) << "Invalid engine IP " << ip_str; | 131 DLOG(FATAL) << "Invalid engine IP " << ip_str; |
132 return Assignment(); | 132 return Assignment(); |
133 } | 133 } |
134 assignment.engine_endpoint = | 134 assignment.assignment_options.engine_endpoint = |
135 net::IPEndPoint(ip_address, base::checked_cast<uint16_t>(port_parsed)); | 135 net::IPEndPoint(ip_address, base::checked_cast<uint16_t>(port_parsed)); |
136 | 136 |
137 std::string transport_str = | 137 std::string transport_str = |
138 cmd_line->GetSwitchValueASCII(switches::kEngineTransport); | 138 cmd_line->GetSwitchValueASCII(switches::kEngineTransport); |
139 if (transport_str == kSSLTransportValue) { | 139 if (transport_str == kSSLTransportValue) { |
140 assignment.transport_protocol = Assignment::TransportProtocol::SSL; | 140 assignment.transport_protocol = Assignment::TransportProtocol::SSL; |
141 } else if (transport_str == kTCPTransportValue) { | 141 } else if (transport_str == kTCPTransportValue) { |
142 assignment.transport_protocol = Assignment::TransportProtocol::TCP; | 142 assignment.transport_protocol = Assignment::TransportProtocol::TCP; |
143 } else if (transport_str == kGrpcTransportValue) { | 143 } else if (transport_str == kGrpcTransportValue) { |
144 assignment.transport_protocol = Assignment::TransportProtocol::GRPC; | 144 assignment.transport_protocol = Assignment::TransportProtocol::GRPC; |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 if (cert_list.size() != 1) { | 359 if (cert_list.size() != 1) { |
360 base::ResetAndReturn(&callback_) | 360 base::ResetAndReturn(&callback_) |
361 .Run(ASSIGNMENT_REQUEST_RESULT_INVALID_CERT, Assignment()); | 361 .Run(ASSIGNMENT_REQUEST_RESULT_INVALID_CERT, Assignment()); |
362 return; | 362 return; |
363 } | 363 } |
364 | 364 |
365 // The assigner assumes SSL-only and all engines it assigns only communicate | 365 // The assigner assumes SSL-only and all engines it assigns only communicate |
366 // over SSL. | 366 // over SSL. |
367 Assignment assignment; | 367 Assignment assignment; |
368 assignment.transport_protocol = Assignment::TransportProtocol::SSL; | 368 assignment.transport_protocol = Assignment::TransportProtocol::SSL; |
369 assignment.engine_endpoint = net::IPEndPoint(ip_address, port); | 369 assignment.assignment_options.engine_endpoint = |
| 370 net::IPEndPoint(ip_address, port); |
370 assignment.client_auth_token = client_auth_token; | 371 assignment.client_auth_token = client_auth_token; |
371 assignment.cert = std::move(cert_list[0]); | 372 assignment.cert = std::move(cert_list[0]); |
372 | 373 |
373 base::ResetAndReturn(&callback_) | 374 base::ResetAndReturn(&callback_) |
374 .Run(ASSIGNMENT_REQUEST_RESULT_OK, assignment); | 375 .Run(ASSIGNMENT_REQUEST_RESULT_OK, assignment); |
375 } | 376 } |
376 | 377 |
377 void AssignmentSource::OnJsonParseError(const std::string& error) { | 378 void AssignmentSource::OnJsonParseError(const std::string& error) { |
378 DLOG(ERROR) << "Error while parsing assigner JSON: " << error; | 379 DLOG(ERROR) << "Error while parsing assigner JSON: " << error; |
379 base::ResetAndReturn(&callback_) | 380 base::ResetAndReturn(&callback_) |
380 .Run(ASSIGNMENT_REQUEST_RESULT_BAD_RESPONSE, Assignment()); | 381 .Run(ASSIGNMENT_REQUEST_RESULT_BAD_RESPONSE, Assignment()); |
381 } | 382 } |
382 | 383 |
383 } // namespace client | 384 } // namespace client |
384 } // namespace blimp | 385 } // namespace blimp |
OLD | NEW |