@@ -24,6 +24,7 @@ module;
24
24
#endif
25
25
26
26
#include < any>
27
+ #include < coroutine>
27
28
#include < filesystem>
28
29
#include < stdexcept>
29
30
#include < system_error>
@@ -129,7 +130,7 @@ static future<file_result> read_fully(const sstring& name, const sstring& what)
129
130
return do_with (std::move (f), [name = std::move (name)](file& f) mutable {
130
131
return f.stat ().then ([&f, name = std::move (name)](struct stat s) mutable {
131
132
return f.dma_read_bulk <char >(0 , s.st_size ).then ([s, name = std::move (name)](temporary_buffer<char > buf) mutable {
132
- return file_result{ std::move (buf), file_info{
133
+ return file_result{ std::move (buf), file_info{
133
134
std::move (name), std::chrono::system_clock::from_time_t (s.st_mtim .tv_sec ) +
134
135
std::chrono::duration_cast<std::chrono::system_clock::duration>(std::chrono::nanoseconds (s.st_mtim .tv_nsec ))
135
136
} };
@@ -223,14 +224,14 @@ class tls::dh_params::impl : gnutlsobj {
223
224
return dh_ptr (params, &gnutls_dh_params_deinit);
224
225
}
225
226
public:
226
- impl (dh_ptr p)
227
- : _params(std::move(p))
227
+ impl (dh_ptr p)
228
+ : _params(std::move(p))
228
229
{}
229
230
impl (level lvl)
230
231
#if GNUTLS_VERSION_NUMBER >= 0x030506
231
232
: _params(nullptr , &gnutls_dh_params_deinit)
232
233
, _sec_param(to_gnutls_level(lvl))
233
- #else
234
+ #else
234
235
: impl([&] {
235
236
auto bits = gnutls_sec_param_to_pk_bits (GNUTLS_PK_DH, to_gnutls_level (lvl));
236
237
auto ptr = new_dh_params ();
@@ -245,14 +246,14 @@ class tls::dh_params::impl : gnutlsobj {
245
246
blob_wrapper w (pkcs3);
246
247
gtls_chk (gnutls_dh_params_import_pkcs3 (ptr.get (), &w, gnutls_x509_crt_fmt_t (fmt)));
247
248
return ptr;
248
- }())
249
+ }())
249
250
{}
250
251
impl (const impl& v)
251
252
: impl([&v] {
252
253
auto ptr = new_dh_params ();
253
254
gtls_chk (gnutls_dh_params_cpy (ptr.get (), v));
254
255
return ptr;
255
- }())
256
+ }())
256
257
{}
257
258
~impl () = default ;
258
259
@@ -854,9 +855,9 @@ class tls::reloadable_credentials_base {
854
855
auto i = _watches.find (e.id );
855
856
if (i != _watches.end ()) {
856
857
auto & filename = i->second .second ;
857
- // only add actual file watches to
858
+ // only add actual file watches to
858
859
// query set. If this was a directory
859
- // watch, the file should already be
860
+ // watch, the file should already be
860
861
// in there.
861
862
if (_all_files.count (filename)) {
862
863
_files[filename] = e.mask ;
@@ -918,7 +919,7 @@ class tls::reloadable_credentials_base {
918
919
} catch (...) {
919
920
if (std::any_of (_files.begin (), _files.end (), [](auto & p) { return p.second == fsnotifier::flags::ignored; })) {
920
921
// if any file in the reload set was deleted - i.e. we have not seen a "closed" yet - assume
921
- // this is a spurious reload and we'd better wait for next event - hopefully a "closed" -
922
+ // this is a spurious reload and we'd better wait for next event - hopefully a "closed" -
922
923
// and try again
923
924
return ;
924
925
}
@@ -931,7 +932,7 @@ class tls::reloadable_credentials_base {
931
932
}
932
933
void on_success () {
933
934
_files.clear ();
934
- // remove all directory watches, since we've successfully
935
+ // remove all directory watches, since we've successfully
935
936
// reloaded -> the file watches themselves should suffice now
936
937
auto i = _watches.begin ();
937
938
auto e = _watches.end ();
@@ -967,7 +968,7 @@ class tls::reloadable_credentials_base {
967
968
future<fsnotifier::watch_token> add_watch (const sstring& filename, fsnotifier::flags flags = fsnotifier::flags::close_write|fsnotifier::flags::delete_self) {
968
969
return _fsn.create_watch (filename, flags).then ([this , filename = filename](fsnotifier::watch w) {
969
970
auto t = w.token ();
970
- // we might create multiple watches for same token in case of dirs, avoid deleting previously
971
+ // we might create multiple watches for same token in case of dirs, avoid deleting previously
971
972
// created one
972
973
if (_watches.count (t)) {
973
974
w.release ();
@@ -1086,15 +1087,15 @@ class session : public enable_lw_shared_from_this<session> {
1086
1087
}
1087
1088
// Maybe set up server session ticket support
1088
1089
switch (_creds->get_session_resume_mode ()) {
1089
- case session_resume_mode::NONE:
1090
+ case session_resume_mode::NONE:
1090
1091
default :
1091
1092
break ;
1092
1093
case session_resume_mode::TLS13_SESSION_TICKET:
1093
1094
gnutls_session_ticket_enable_server (*this , _creds->get_session_resume_key ());
1094
1095
break ;
1095
1096
}
1096
1097
}
1097
-
1098
+
1098
1099
auto prio = _creds->get_priority ();
1099
1100
if (prio) {
1100
1101
gtls_chk (gnutls_priority_set (*this , prio));
@@ -1307,7 +1308,7 @@ class session : public enable_lw_shared_from_this<session> {
1307
1308
ss << stat_str;
1308
1309
if (stat_str.back () != ' ' ) {
1309
1310
ss << ' ' ;
1310
- }
1311
+ }
1311
1312
ss << " (Issuer=[" << dn->issuer << " ], Subject=[" << dn->subject << " ])" ;
1312
1313
stat_str = ss.str ();
1313
1314
}
@@ -1584,8 +1585,8 @@ class session : public enable_lw_shared_from_this<session> {
1584
1585
std::bind (&session::do_shutdown, this )).then (
1585
1586
std::bind (&session::wait_for_eof, this )).finally ([me = shared_from_this ()] {});
1586
1587
// note moved finally clause above. It is theorethically possible
1587
- // that we could complete do_shutdown just before the close calls
1588
- // below, get pre-empted, have "close()" finish, get freed, and
1588
+ // that we could complete do_shutdown just before the close calls
1589
+ // below, get pre-empted, have "close()" finish, get freed, and
1589
1590
// then call wait_for_eof on stale pointer.
1590
1591
}
1591
1592
void close () noexcept {
@@ -1604,17 +1605,18 @@ class session : public enable_lw_shared_from_this<session> {
1604
1605
future<> close_after_shutdown () {
1605
1606
_eof = true ;
1606
1607
try {
1607
- ( void ) _in.close (). handle_exception ([](std::exception_ptr) {} ); // should wake any waiters
1608
+ co_await _in.close (); // should wake any waiters
1608
1609
} catch (...) {
1609
1610
}
1610
1611
try {
1611
- ( void ) _out.close (). handle_exception ([](std::exception_ptr) {} );
1612
+ co_await _out.close ();
1612
1613
} catch (...) {
1613
1614
}
1615
+
1614
1616
// make sure to wait for handshake attempt to leave semaphores. Must be in same order as
1615
1617
// handshake aqcuire, because in worst case, we get here while a reader is attempting
1616
1618
// re-handshake.
1617
- return with_semaphore (_in_sem, 1 , [this ] {
1619
+ co_await with_semaphore (_in_sem, 1 , [this ] {
1618
1620
return with_semaphore (_out_sem, 1 , [] {});
1619
1621
});
1620
1622
}
@@ -1659,13 +1661,13 @@ class session : public enable_lw_shared_from_this<session> {
1659
1661
future<session_data> get_session_resume_data () {
1660
1662
return state_checked_access ([this ] {
1661
1663
/* *
1662
- * Session ticket data is not available just because handshake
1664
+ * Session ticket data is not available just because handshake
1663
1665
* was done. First off, of course other part must support it,
1664
1666
* but we also (mostly?) need to actually transfer data before
1665
1667
* the ticket is received.
1666
- *
1668
+ *
1667
1669
* Check session flags so we can return no data in the case
1668
- * none is avail. Gnutls returns a 4-byte "empty marker"
1670
+ * none is avail. Gnutls returns a 4-byte "empty marker"
1669
1671
* on none avail.
1670
1672
*/
1671
1673
auto flags = gnutls_session_get_flags (*this );
@@ -1681,7 +1683,7 @@ class session : public enable_lw_shared_from_this<session> {
1681
1683
return state_checked_access ([this ] {
1682
1684
return extract_dn_information ();
1683
1685
});
1684
- }
1686
+ }
1685
1687
future<std::vector<subject_alt_name>> get_alt_name_information (std::unordered_set<subject_alt_name_type> types) {
1686
1688
return state_checked_access ([this ](std::unordered_set<subject_alt_name_type> types) {
1687
1689
std::vector<subject_alt_name> res;
0 commit comments