Skip to content

Commit

Permalink
configurable keep-alive timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
dr7ana committed Dec 14, 2023
1 parent a2a6310 commit 89d85ff
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
11 changes: 7 additions & 4 deletions include/quic/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ namespace oxen::quic
struct user_config
{
// max streams
uint64_t max_streams = 0;
uint64_t max_streams{0};
// keep alive timeout
std::chrono::milliseconds keep_alive{0ms};
// datagram support
bool datagram_support = false;
bool datagram_support{false};
// datagram splitting support
bool split_packet = false;
bool split_packet{false};
// splitting policy
Splitting policy = Splitting::NONE;
Splitting policy{Splitting::NONE};

user_config() = default;
};
Expand Down Expand Up @@ -59,6 +61,7 @@ namespace oxen::quic
private:
void handle_ioctx_opt(std::shared_ptr<TLSCreds> tls);
void handle_ioctx_opt(opt::max_streams ms);
void handle_ioctx_opt(opt::keep_alive ka);
void handle_ioctx_opt(stream_data_callback func);
void handle_ioctx_opt(stream_open_callback func);
void handle_ioctx_opt(stream_close_callback func);
Expand Down
17 changes: 13 additions & 4 deletions include/quic/opt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@

namespace oxen::quic::opt
{
using namespace std::chrono_literals;

struct max_streams
{
uint64_t stream_count = DEFAULT_MAX_BIDI_STREAMS;
uint64_t stream_count{DEFAULT_MAX_BIDI_STREAMS};
max_streams() = default;
explicit max_streams(uint64_t s) : stream_count{s} {}
};

struct keep_alive
{
std::chrono::milliseconds time{0ms};
keep_alive() = default;
explicit keep_alive(std::chrono::milliseconds val) : time{val} {}
};

/// This can be initialized a few different ways. Simply passing a default constructed struct
/// to Network::Endpoint(...) will enable datagrams without packet-splitting. From there, pass
/// `Splitting::ACTIVE` to the constructor to enable packet-splitting.
Expand All @@ -36,10 +45,10 @@ namespace oxen::quic::opt
/// destroyed and re-initialized with the desired settings.
struct enable_datagrams
{
bool split_packets = false;
Splitting mode = Splitting::NONE;
bool split_packets{false};
Splitting mode{Splitting::NONE};
// Note: this is the size of the entire buffer, divided amongst 4 rows
int bufsize = 4096;
int bufsize{4096};

enable_datagrams() = default;
explicit enable_datagrams(bool e) = delete;
Expand Down
2 changes: 2 additions & 0 deletions src/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,8 @@ namespace oxen::quic
throw std::runtime_error{"Failed to initialize connection object: "s + ngtcp2_strerror(rv)};
}

ngtcp2_conn_set_keep_alive_timeout(connptr, context->config.keep_alive.count());

tls_session = tls_creds->make_session(is_outbound, alpns);

if (remote_pk)
Expand Down
6 changes: 6 additions & 0 deletions src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ namespace oxen::quic
log::trace(log_cat, "User passed max_streams_bidi config value: {}", config.max_streams);
}

void IOContext::handle_ioctx_opt(opt::keep_alive ka)
{
config.keep_alive = ka.time;
log::trace(log_cat, "User passed connection keep_alive config value: {}", config.keep_alive.count());
}

void IOContext::handle_ioctx_opt(stream_data_callback func)
{
log::trace(log_cat, "IO context stored stream close callback");
Expand Down

0 comments on commit 89d85ff

Please sign in to comment.