diff options
author | Julan Hsu <julanhsu@google.com> | 2017-01-26 10:52:55 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-02-02 12:29:26 -0800 |
commit | 2a5afe35a39f9ca98480da2f8584179e6b62d8fd (patch) | |
tree | 7ea4c73b9f1571bb454a550ef75ba5fdd13490c4 /brillo | |
parent | e2743693963e3e5d79bb44951eb9cbc1a99233a1 (diff) | |
download | platform_external_libbrillo-2a5afe35a39f9ca98480da2f8584179e6b62d8fd.tar.gz platform_external_libbrillo-2a5afe35a39f9ca98480da2f8584179e6b62d8fd.tar.bz2 platform_external_libbrillo-2a5afe35a39f9ca98480da2f8584179e6b62d8fd.zip |
http_transport_curl: add an API to bind IP address
Gale mesh child devices change IP address during the GrOOBE setup phase.
This causes buffet to lose connection to cloud for sometime. This CL
allows buffet to bind the curl requests to the new IP address.
BUG=b:32510317
TEST=manually on gale. Groobe test from App.
CQ-DEPEND=CL:*322183
Change-Id: I84ac5f92bcad0190a30afc2b547280debc31d8e3
Reviewed-on: https://chromium-review.googlesource.com/433462
Commit-Ready: Julan Hsu <julanhsu@google.com>
Tested-by: Julan Hsu <julanhsu@google.com>
Reviewed-by: Srinivasa duvvuri <sduvvuri@chromium.org>
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Diffstat (limited to 'brillo')
-rw-r--r-- | brillo/http/http_transport.h | 3 | ||||
-rw-r--r-- | brillo/http/http_transport_curl.cc | 8 | ||||
-rw-r--r-- | brillo/http/http_transport_curl.h | 3 | ||||
-rw-r--r-- | brillo/http/http_transport_fake.h | 2 | ||||
-rw-r--r-- | brillo/http/mock_transport.h | 1 |
5 files changed, 17 insertions, 0 deletions
diff --git a/brillo/http/http_transport.h b/brillo/http/http_transport.h index 63e135c..c048422 100644 --- a/brillo/http/http_transport.h +++ b/brillo/http/http_transport.h @@ -82,6 +82,9 @@ class BRILLO_EXPORT Transport : public std::enable_shared_from_this<Transport> { // Set the default timeout of requests made. virtual void SetDefaultTimeout(base::TimeDelta timeout) = 0; + // Set the local IP address of requests + virtual void SetLocalIpAddress(const std::string& ip_address) = 0; + // Creates a default http::Transport (currently, using http::curl::Transport). static std::shared_ptr<Transport> CreateDefault(); diff --git a/brillo/http/http_transport_curl.cc b/brillo/http/http_transport_curl.cc index f7e3b71..0cf902f 100644 --- a/brillo/http/http_transport_curl.cc +++ b/brillo/http/http_transport_curl.cc @@ -164,6 +164,10 @@ std::shared_ptr<http::Connection> Transport::CreateConnection( static_cast<int>(timeout_ms)); } } + if (code == CURLE_OK && !ip_address_.empty()) { + code = curl_interface_->EasySetOptStr( + curl_handle, CURLOPT_INTERFACE, ip_address_.c_str()); + } // Setup HTTP request method and optional request body. if (code == CURLE_OK) { @@ -264,6 +268,10 @@ void Transport::SetDefaultTimeout(base::TimeDelta timeout) { connection_timeout_ = timeout; } +void Transport::SetLocalIpAddress(const std::string& ip_address) { + ip_address_ = "host!" + ip_address; +} + void Transport::AddEasyCurlError(brillo::ErrorPtr* error, const tracked_objects::Location& location, CURLcode code, diff --git a/brillo/http/http_transport_curl.h b/brillo/http/http_transport_curl.h index 0a95c63..518ee9d 100644 --- a/brillo/http/http_transport_curl.h +++ b/brillo/http/http_transport_curl.h @@ -59,6 +59,8 @@ class BRILLO_EXPORT Transport : public http::Transport { void SetDefaultTimeout(base::TimeDelta timeout) override; + void SetLocalIpAddress(const std::string& ip_address) override; + // Helper methods to convert CURL error codes (CURLcode and CURLMcode) // into brillo::Error object. static void AddEasyCurlError(brillo::ErrorPtr* error, @@ -127,6 +129,7 @@ class BRILLO_EXPORT Transport : public http::Transport { RequestID last_request_id_{0}; // The connection timeout for the requests made. base::TimeDelta connection_timeout_; + std::string ip_address_; base::WeakPtrFactory<Transport> weak_ptr_factory_for_timer_{this}; base::WeakPtrFactory<Transport> weak_ptr_factory_{this}; diff --git a/brillo/http/http_transport_fake.h b/brillo/http/http_transport_fake.h index ac8bc2a..e894c32 100644 --- a/brillo/http/http_transport_fake.h +++ b/brillo/http/http_transport_fake.h @@ -102,6 +102,8 @@ class Transport : public http::Transport { void SetDefaultTimeout(base::TimeDelta timeout) override; + void SetLocalIpAddress(const std::string& ip_address) override {} + private: // A list of user-supplied request handlers. std::map<std::string, HandlerCallback> handlers_; diff --git a/brillo/http/mock_transport.h b/brillo/http/mock_transport.h index 9bc6c14..040d20e 100644 --- a/brillo/http/mock_transport.h +++ b/brillo/http/mock_transport.h @@ -33,6 +33,7 @@ class MockTransport : public Transport { const ErrorCallback&)); MOCK_METHOD1(CancelRequest, bool(RequestID)); MOCK_METHOD1(SetDefaultTimeout, void(base::TimeDelta)); + MOCK_METHOD1(SetLocalIpAddress, void(const std::string&)); private: DISALLOW_COPY_AND_ASSIGN(MockTransport); |