Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify and bisect the session end timer.
Browse files Browse the repository at this point in the history
The session ending of DoQ and of the tcp-based mode is slightly
different, putting them in the same function resulted in obscure code.
VanStratum committed Aug 29, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 06c1db2 commit f0cba21
Showing 2 changed files with 48 additions and 34 deletions.
80 changes: 46 additions & 34 deletions flame/trafgen.cpp
Original file line number Diff line number Diff line change
@@ -278,47 +278,59 @@ void TrafGen::start_wait_timer_for_session_finish()
_finish_session_timer->on<uvw::TimerEvent>([this, wait_time_start](const uvw::TimerEvent &event,
uvw::TimerHandle &h) {
auto now = std::chrono::high_resolution_clock::now();
auto cur_wait_ms = std::chrono::duration_cast<std::chrono::milliseconds>(now - wait_time_start).count();

//TODO: put the end of the quic session in a dedicated function
#ifdef DOQ_ENABLE
if ( (((_traf_config->protocol != Protocol::QUIC) && !_started_sending) || this->in_flight()) && (cur_wait_ms < (_traf_config->r_timeout * 1000))) {
#else
if ( (!_started_sending || this->in_flight()) && (cur_wait_ms < (_traf_config->r_timeout * 1000))) {
#endif
// queries in flight and timeout time not elapsed, still wait
return;
} else if (cur_wait_ms < (_traf_config->s_delay)) {
// either timed out or nothing in flight. ensure delay period has passed
// before restarting
return;
}

// shut down timer and connection. TCP CloseEvent will handle restarting sends.
_finish_session_timer->stop();
_started_sending = false;
_tcp_handle->stop();
_finish_session_timer->close();

int cur_wait_ms = std::chrono::duration_cast<std::chrono::milliseconds>(now - wait_time_start).count();
#ifdef DOQ_ENABLE
if (_traf_config->protocol == Protocol::DOQ) {
_quic_session->close();
_quic_session.reset();
handle_timeouts(true);
_finish_session_timer.reset();
if (!_stopping)
start_quic_session();
} else
if (_traf_config->protocol == Protocol::DOQ)
finish_quic_session(cur_wait_ms);
else
#endif
{
_tcp_handle->close();
}
finish_tcp_session(cur_wait_ms);
});
_finish_session_timer->start(uvw::TimerHandle::Time{1}, uvw::TimerHandle::Time{50});
}

void TrafGen::finish_tcp_session(int cur_wait_ms)
{
if ( (!_started_sending || this->in_flight()) && (cur_wait_ms < (_traf_config->r_timeout * 1000))) {
// queries in flight and timeout time not elapsed, still wait
return;
} else if (cur_wait_ms < (_traf_config->s_delay)) {
// either timed out or nothing in flight. ensure delay period has passed
// before restarting
return;
}

// shut down timer and connection. TCP CloseEvent will handle restarting sends.
_finish_session_timer->stop();
_started_sending = false;
_tcp_handle->stop();
_finish_session_timer->close();
_tcp_handle->close();
}

#ifdef DOQ_ENABLE

void TrafGen::finish_quic_session(int cur_wait_ms)
{
if ( ( this->in_flight()) && (cur_wait_ms < (_traf_config->r_timeout * 1000))) {
// queries in flight and timeout time not elapsed, still wait
return;
} else if (cur_wait_ms < (_traf_config->s_delay)) {
// either timed out or nothing in flight. ensure delay period has passed
// before restarting
return;
}

_finish_session_timer->stop();
_finish_session_timer->close();

_quic_session->close();
_quic_session.reset();
handle_timeouts(true);
if (!_stopping)
start_quic_session();
}

void TrafGen::start_quic_session()
{

@@ -337,7 +349,7 @@ void TrafGen::start_quic_session()
_metrics->receive(_open_streams[i.first].send_time, 2, _open_streams.size());
}
};
// The pending requests are simly cleared because they are not yet sent if
// The pending requests are simply cleared because they are not yet sent if
// this event occurs
auto conn_refused = [this]() {
_open_streams.clear();
2 changes: 2 additions & 0 deletions flame/trafgen.h
Original file line number Diff line number Diff line change
@@ -105,12 +105,14 @@ class TrafGen
void connect_tcp_events();
void start_tcp_session();
void start_wait_timer_for_session_finish();
void finish_tcp_session(int cur_wait_ms);

bool in_flight();

#ifdef DOQ_ENABLE
void start_quic();
void start_quic_session();
void finish_quic_session(int cur_wait_ms);
#endif

public:

0 comments on commit f0cba21

Please sign in to comment.