Skip to content

Commit 08a4666

Browse files
[release/6.x] Cherry-pick: Reuse curl handle to attempt to reuse sessions (#7321) (#7332)
Co-authored-by: cjen1-msft <chrisjensen@microsoft.com>
1 parent a44ba40 commit 08a4666

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [6.0.16]
9+
10+
[6.0.16]: https://github.com/microsoft/CCF/releases/tag/6.0.16
11+
12+
### Changed
13+
14+
- Snapshot fetching attempts to re-use the TLS sessions whenever possible (#7321)
15+
816
## [6.0.15]
917

1018
[6.0.15]: https://github.com/microsoft/CCF/releases/tag/6.0.15

python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "ccf"
7-
version = "6.0.15"
7+
version = "6.0.16"
88
authors = [
99
{ name="CCF Team", email="CCF-Sec@microsoft.com" },
1010
]

src/http/curl.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,20 @@ namespace ccf::curl
6363
}
6464
}
6565

66+
// No implicit copying: unique ownership of the CURL handle
67+
UniqueCURL(const UniqueCURL&) = delete;
68+
UniqueCURL& operator=(const UniqueCURL&) = delete;
69+
70+
// Move semantics
71+
UniqueCURL(UniqueCURL&& other) noexcept : p(std::move(other.p)) {}
72+
UniqueCURL& operator=(UniqueCURL&& other) noexcept
73+
{
74+
p = std::move(other.p);
75+
return *this;
76+
}
77+
78+
~UniqueCURL() = default;
79+
6680
operator CURL*() const
6781
{
6882
return p.get();
@@ -493,6 +507,11 @@ namespace ccf::curl
493507
return curl_handle;
494508
}
495509

510+
[[nodiscard]] UniqueCURL& get_easy_handle_ptr()
511+
{
512+
return curl_handle;
513+
}
514+
496515
[[nodiscard]] RESTVerb get_method() const
497516
{
498517
return method;

src/snapshots/fetch.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ namespace snapshots
5050
// Make initial request, which returns a redirect response to specific
5151
// snapshot
5252
std::string snapshot_url;
53+
ccf::curl::UniqueCURL curl_easy;
5354
{
54-
ccf::curl::UniqueCURL curl_easy;
5555
curl_easy.set_opt(CURLOPT_CAINFO, path_to_peer_cert.c_str());
5656

5757
auto initial_url = fmt::format(
@@ -117,12 +117,12 @@ namespace snapshots
117117

118118
snapshot_url =
119119
fmt::format("https://{}{}", peer_address, location_it->second);
120+
curl_easy = std::move(request->get_easy_handle_ptr());
120121
}
121122

122123
// Make follow-up request to redirected URL, to fetch total content size
123124
size_t content_size = 0;
124125
{
125-
ccf::curl::UniqueCURL curl_easy;
126126
curl_easy.set_opt(CURLOPT_CAINFO, path_to_peer_cert.c_str());
127127

128128
ccf::curl::UniqueSlist headers;
@@ -194,6 +194,7 @@ namespace snapshots
194194
snapshot_size_request->get_url(),
195195
ec));
196196
}
197+
curl_easy = std::move(snapshot_size_request->get_easy_handle_ptr());
197198
}
198199

199200
// Fetch 4MB chunks at a time
@@ -212,7 +213,6 @@ namespace snapshots
212213

213214
while (true)
214215
{
215-
ccf::curl::UniqueCURL curl_easy;
216216
curl_easy.set_opt(CURLOPT_CAINFO, path_to_peer_cert.c_str());
217217

218218
ccf::curl::UniqueSlist headers;
@@ -266,6 +266,7 @@ namespace snapshots
266266

267267
snapshot_response =
268268
std::move(snapshot_range_request->get_response_ptr());
269+
curl_easy = std::move(snapshot_range_request->get_easy_handle_ptr());
269270

270271
if (range_end == content_size)
271272
{

0 commit comments

Comments
 (0)